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
 Find value closest to another value in dif wks

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
Noname123 Posted - 04/06/2022 : 06:57:17 AM
So I'd like to go through all the values of a certain column in wks1 and for each row value I'd like to:
1)Find closest value in indicated column1 in wks2
2)then when I get the index for the value, I'd like to find maximum of column2 from the range [index-4;index+4] and then simply store the maximum row.
Is this even possible in labTalk? And if so, how could I possible do this?
3   L A T E S T    R E P L I E S    (Newest First)
YimingChen Posted - 04/12/2022 : 4:54:37 PM
Try the script on the attached workbook.


range r1 = wks2!col("column1");
range r2 = wks1!col(A); 
range r3 = wks1!col("Column2");
dataset ds;
dataset ds1;
ds.SetSize(r2.nrows);
ds1.SetSize(r2.nrows);
for (int i = 1; i <= r2.nrows; i++) {
	int idx = 1;
	for (int j = 1; j <= r1.nrows; j++) {
		if (abs(r2[i] - r1[j]) < abs(r2[i] - r1[idx])) {
			idx = j;
		}
	}
	ds[i] = idx;
	
	int start = idx - 4;
	start = start > 0 ? start : 1;
	int end = idx + 4;
	end = end < r3.nrows ? end : r3.nrows;
	range rtmp = wks1!col("Column2")[$(start):$(end)];
	ds1[i] = max(rtmp);
}
range r4 = wks1!col(C); 
r4 = ds;
range r5 = wks1!col(D);
r5 = ds1;

https://my.originlab.com/ftp/forum_and_kbase/Images/SearchSample.ogwu

James
Noname123 Posted - 04/10/2022 : 11:27:43 AM
But that only works, if the columns are of the same length, but in my case, the first column is much longer. Besides, I'd like to do it for multiple worksheets, so labtalk would be much better.
YimingChen Posted - 04/07/2022 : 2:49:53 PM
Please check the attached project file. If you can put all columns in one worksheet, you can set formula for the column to calculate.

https://my.originlab.com/ftp/forum_and_kbase/Images/Search.ogwu

James

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