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
 All Forums
 Origin Forum for Programming
 LabTalk Forum
 Help a noob loop in LabTalk

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

Screensize:
UserName:
Password:
Anti-Spam Code:
Format Mode:
Format: BoldItalicizedUnderlineStrikethrough Align LeftCenteredAlign Right Horizontal Rule Insert HyperlinkUpload FileInsert Image Insert CodeInsert QuoteInsert List
   
Message:

* HTML is OFF
* Forum Code is ON
Smilies
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Clown [:o)]
Black Eye [B)] Eight Ball [8] Frown [:(] Shy [8)]
Shocked [:0] Angry [:(!] Dead [xx(] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

T O P I C    R E V I E W
phike Posted - 01/27/2023 : 10:34:51 AM
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
2   L A T E S T    R E P L I E S    (Newest First)
phike Posted - 02/07/2023 : 11:32:21 AM
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

YimingChen Posted - 01/30/2023 : 09:46:37 AM
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

The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000