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
 Find value closest to another value in dif wks
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

Noname123

Armenia
16 Posts

Posted - 04/06/2022 :  06:57:17 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
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?

YimingChen

1665 Posts

Posted - 04/07/2022 :  2:49:53 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
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
Go to Top of Page

Noname123

Armenia
16 Posts

Posted - 04/10/2022 :  11:27:43 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
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.
Go to Top of Page

YimingChen

1665 Posts

Posted - 04/12/2022 :  4:54:37 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
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
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