Author |
Topic  |
|
SmallMike
Austria
3 Posts |
Posted - 04/21/2022 : 02:36:14 AM
|
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
|
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 |
 |
|
SmallMike
Austria
3 Posts |
Posted - 04/22/2022 : 10:49:37 AM
|
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 |
 |
|
aplotnikov
Germany
169 Posts |
Posted - 04/25/2022 : 3:20:23 PM
|
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 |
 |
|
YimingChen
1666 Posts |
|
YimingChen
1666 Posts |
Posted - 04/25/2022 : 5:32:37 PM
|
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 |
 |
|
SmallMike
Austria
3 Posts |
Posted - 05/02/2022 : 07:01:21 AM
|
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 |
 |
|
aplotnikov
Germany
169 Posts |
Posted - 05/11/2022 : 08:50:01 AM
|
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
|
 |
|
YimingChen
1666 Posts |
Posted - 05/11/2022 : 11:50:18 AM
|
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 |
 |
|
aplotnikov
Germany
169 Posts |
Posted - 05/11/2022 : 2:44:49 PM
|
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>).

|
 |
|
YimingChen
1666 Posts |
Posted - 05/11/2022 : 4:23:22 PM
|
B[idx(col(A) == 1)] |
 |
|
aplotnikov
Germany
169 Posts |
Posted - 05/11/2022 : 4:56:28 PM
|
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:
 |
 |
|
YimingChen
1666 Posts |
Posted - 05/11/2022 : 5:13:48 PM
|
It seems like a bug. I will report.
James |
 |
|
aisahoga
1 Posts |
Posted - 05/24/2022 : 09:11:42 AM
|
thank you for the reply and the suggestion.
|
 |
|
|
Topic  |
|