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
 Iterate rows and post results to other column
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

SmallMike

Austria
3 Posts

Posted - 04/21/2022 :  02:36:14 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Hello all,

I am quite new to origin and there might be easy ways to do the following; however, I have not found a solution yet.

This is what I want to implement:

  • Step 1: iterate through Column A and find all indexes with value xxx

  • Step 2: get the values of Column B at the indexes obtained in step 1

  • Step 3: store those values of Step 2 in Column C


You can find the "Before formula script" that I have written below.

The open questions are:

  • What sort of variable should valsD be?

  • The valsD array will have a different size to columns A and B. Does origin support this?


Looking forward to any help or hints on how to approach this.

Cheers

Mikel

--------------------------------------------------------------
Column formula
Col(D)= valsD

Before Formula Script
________________________________
range posX=wcol(1);
range posY=wcol(2);
nrows = posX.GetSize(); // Get the number of rows
int indexVal=0;

variableType valsD;

for(int ii = 0; ii < nrows; ii ++)
{
if(posX[ii]==3600){
valsD[indexVal]=posY[ii]
indexVal=indexVal+1;}
}
________________________

Operating System: OriginPro 2021b (64-bit) 9.8.5.201

aplotnikov

Germany
169 Posts

Posted - 04/21/2022 :  06:13:12 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
You can use either "wextract" X-function:
wextract settings.stCondition.Condition:="col(A)==<xxx>" settings.Cols:=1

or "wxt" X-function to mark rows according the condition for col(A) and then "wcopy" X-function to copy data from selected rows (col(A) and col(B) are supposed to be in the same worksheet):
wxt test:="col(A)==<xxx>" sel:=1;
wcopy rowselected:=1 ow:=<new>


You can specify the output worksheet /dataset if necessary.

Edited by - aplotnikov on 04/21/2022 06:13:41 AM
Go to Top of Page

SmallMike

Austria
3 Posts

Posted - 04/22/2022 :  10:49:37 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hello Aplotnikov,

thank you for the reply and the suggestion.

Three follow up question/comment from my side:
  • Is it possible to do it with the "for" loop that I have shown in my first post? This looks for me more intuitive

  • I have tried to use the functiones that you have recommended but without success. Can they be used in this "formula before script"? I get completely unexpected results/outcomes

  • What do you recommend: try to learn the labtalk language or just try to find a workaround with python?


At first glance and in my opinion as a newbie, Labtalk language seems overly complicated and not worth the effort to learn. Specially considering that other tools such as Jupyter Notebook offer good capabilites with a more attractive and intuitive language.

Thanks for the support
Grüße

Mikel
Go to Top of Page

aplotnikov

Germany
169 Posts

Posted - 04/25/2022 :  3:20:23 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Mikel,

1. The use of explicit for-loops is less efficient - try to avoid it if possible.
2. Use Command Line (Alt-3) to call X-functions or scripts. Please read carefully the documentation on the suggested X-functions - it is quite comprehensive.
3. There is no common answer on this question. It depends on your purposes. In my particular opinion Labtalk has certain advantages if you use Origin - it looks a bit esoteric sometimes, but is very concise. The replacements of Origin are beyond the forum topics here.

Regards,

Alexei
Go to Top of Page

YimingChen

1666 Posts

Posted - 04/25/2022 :  5:15:47 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
You can use the LabTalk function idx() to get the indices. See the example below:


We added this function in Origin 2021b.
https://www.originlab.com/ReleaseNotes/detail.aspx?id=2021b6ORG-23290

James
Go to Top of Page

YimingChen

1666 Posts

Posted - 04/25/2022 :  5:32:37 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Please also check the Python solution:
FYI: the docstring '''F:FF''' is to show the parameters are passed as vectors. It is not necessary though as that is the default.


James

Edited by - YimingChen on 04/25/2022 5:36:05 PM
Go to Top of Page

SmallMike

Austria
3 Posts

Posted - 05/02/2022 :  07:01:21 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Thank you very much for your suggestions. They are very helfpul to understand the logic of Origin.

I will have a few trials and go through the documentation to get a beter grasp of how Origin works.

Cheers
Mike
Go to Top of Page

aplotnikov

Germany
169 Posts

Posted - 05/11/2022 :  08:50:01 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
quote:
Originally posted by YimingChen

You can use the LabTalk function idx() to get the indices. See the example below:




Hi James,

how should I specify the Boolean expression if the conventional Labtalk cell notation is used? I tried various combinations without any success.

Regards,

Alexei
Go to Top of Page

YimingChen

1666 Posts

Posted - 05/11/2022 :  11:50:18 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
I am not sure if I understand your question correctly. you can set the condition in cell formula like = A1 == 1 like you set other variables.

James
Go to Top of Page

aplotnikov

Germany
169 Posts

Posted - 05/11/2022 :  2:44:49 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
I do not use spreadsheet cell notation - I prefer normal old-fashioned column names instead of Excel-style letters to improve readability of scripts.
How should I use the idx() function in this case? idx(col(<column_name>)==<value>) does not work as well as idx(<book_name>_<column_name>==<value>).


Go to Top of Page

YimingChen

1666 Posts

Posted - 05/11/2022 :  4:23:22 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
B[idx(col(A) == 1)]
Go to Top of Page

aplotnikov

Germany
169 Posts

Posted - 05/11/2022 :  4:56:28 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Just create a workbook with unchecked spreadsheet cell notation and rename columns like "id", "name", "power", etc. Then try to use idx() function. It doesn't work:
Go to Top of Page

YimingChen

1666 Posts

Posted - 05/11/2022 :  5:13:48 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
It seems like a bug. I will report.

James
Go to Top of Page

aisahoga

1 Posts

Posted - 05/24/2022 :  09:11:42 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
thank you for the reply and the suggestion.
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