The Origin Forum
File Exchange
Try Origin for Free
The Origin Forum
Home | Profile | Register | Active Topics | Members | Search | FAQ | Send File to Tech support
Username:
Password:
Save Password
Forgot your Password? | Admin Options

 All Forums
 Origin Forum for Programming
 LabTalk Forum
 Help a noob loop in LabTalk
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

phike

Germany
2 Posts

Posted - 01/27/2023 :  10:34:51 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
OriginPro 2019b
9.6.5.169
Win10

Hey guys,
I'm an absolute LabTalk newcomer and got stuck on a simple sounding issue:

I need to simulate some data.
Here I got a random number generator, that gives me data which I feed into my calculations.
Now I want to repeat this process of "Take Seed from B[i]" -> "Do calculation" -> "Take result and write it into a fiel X[i]"

The issue I face is that in order to do my full calculation, I need the script to actually fill the calculation-coloums fully before I can proceed to the next seed (I need to sum up a specific number of rows).

I attached a small sample.
https://my.originlab.com/ftp/forum_and_kbase/Images/Help-Loop.opju

Hopefully someone can help me.

Thanks in advance and greetings,
Philip

YimingChen

1594 Posts

Posted - 01/30/2023 :  09:46:37 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
The seed to the rnd() has to be integer, see the page below:
https://www.originlab.com/doc/OriginC/ref/rnd

You may define a LabTalk function that takes the seed value as input. See below:




function double cal(int seed) {
  if (rnd(seed)==0) {
   	Dataset ds1 = {rnd(), rnd(), rnd(), rnd(), rnd()};
	Dataset ds2 = {rnd(), rnd(), rnd(), rnd(), rnd()};
	Dataset sum = ds1 + ds2;
	ds1 = ds1 / sum;
	ds2 = ds2 / sum;
	Dataset res = sum((ds1 - ds2)^2);
    return res[5];
  }
  return -1;
}


James
Go to Top of Page

phike

Germany
2 Posts

Posted - 02/07/2023 :  11:32:21 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Awesome ! Thank you a lot, James :)


quote:
Originally posted by YimingChen

The seed to the rnd() has to be integer, see the page below:
https://www.originlab.com/doc/OriginC/ref/rnd

You may define a LabTalk function that takes the seed value as input. See below:




function double cal(int seed) {
  if (rnd(seed)==0) {
   	Dataset ds1 = {rnd(), rnd(), rnd(), rnd(), rnd()};
	Dataset ds2 = {rnd(), rnd(), rnd(), rnd(), rnd()};
	Dataset sum = ds1 + ds2;
	ds1 = ds1 / sum;
	ds2 = ds2 / sum;
	Dataset res = sum((ds1 - ds2)^2);
    return res[5];
  }
  return -1;
}


James

Go to Top of Page
  Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000