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
 questions with xindex
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

circumvent

Posts

Posted - 06/01/2009 :  4:35:25 PM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Origin Ver. and Service Release (Select Help-->About Origin): 8.0 SR3
Operating System: Vista

Hi,

I have a question with the labtalk function xindex, it seems that it does not work as it supposed to be.

A quick example, I have XY dataset
X Y
1 3
2 4
3 7
4 10
5 11

The following command will give

a=xindex(3,book1_b);
a=; #a=3 Should it be 1 since it's the first row?

a=xindex(4,book1_b);
a=; #a=4 Should it be 2 since it's the second row?

a=xindex(5,book7_b);
a=; #a=5

a=xindex(6,book7_b);
a=; #a=5

artem

USA
Posts

Posted - 06/01/2009 :  5:26:32 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
xindex looks at the values of x, not y. Use list(value, dataset) to get the index of the first cell in dataset that is equal to value.

From the Help file:
"The list(value, dataset) function returns the index number in dataset where value first occurs. If there is no match, the function returns 0. Note that this function makes an exact comparison using the equal (==) operator."

Tony
Go to Top of Page

circumvent

Posts

Posted - 06/01/2009 :  5:54:03 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Tony,

Thanks for you reply, but list(value, dataset) is not working because I am not looking for the exact value. I hope the function could return the index of the data equal or smaller than value.

For the xindex, even I only have one column with dataset
0.1
0.2
0.3
1.2
1.2
3
3.5
5.1
5.2


The command
a=xindex(3,book1_b);
a=; will give 3 again. Something must be wrong here.
Go to Top of Page

cpyang

USA
1406 Posts

Posted - 06/03/2009 :  11:11:21 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
There is a Table function that you can use, but you must have another column that contains index, which seems to be the case as shown in your ealier code

a=int(table(book1_b, book1_a, x))

It seems that the Table function was not documented in Origin 8, but here is the info

y = Table(sx, sy, x)

where sx is the dataset name of the independent vector and sy the dependent vector and it interpolates sy vs sx to find y-value at given x-value.

CP
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