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
 limit function anomaly :limit.size
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

andrewdsto

Australia
Posts

Posted - 07/24/2013 :  04:49:45 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Origin Ver. 9.0 and Service Release (Select Help-->About Origin):
Operating System: Windows XP 64 bit

Just a question regarding the limit function returning the rows in column of a dataset rather than actual number of elements in the dataset.

In particular to the limit.size value.


An example is below

I create a simple worksheet: Book1 with an X and Y column. X has 11 entries numbered 1 to 11, the Y column has 10 random numbers.

I run the following code:

win -a book1;
range rr = 2;
limit rr;
ls=limit.size;
type;
type "return the size and min value of rr";
limit.ymin=;
limit.imin=;
limit.size=;
ls=;

range bb = 2[$(ls/2+1)]:1[$(ls)];
limit bb;
type;
type "return the size and min value of bb";
limit.ymin=;
limit.imin=;
limit.size=;

type;
type "return the number of elements in the x column";
%p=xof(rr);
limit %p;
limit.size=;

type;
type "show col and data values";
for (ii=1; ii<=limit.size; ii++) {
rr[$(ii)]=;
bb[$(ii)]=;
type;
};

type;
type "try checking on subset of column directly :- Book1_B -b 6 -e 9";
limit Book1_B -b 6 -e 9;
limit.size=;


This code returns the following results:

return the size and min value of rr
limit.ymin=2.4
limit.imin=2
limit.size=10
ls=10

return the size and min value of bb
limit.ymin=3.3
limit.imin=8
limit.size=10

return the number of elements in the x column
limit.size=11

show col and data values
rr[1]=4.6
bb[1]=5.6

rr[2]=2.4
bb[2]=7.5

rr[3]=7.8
bb[3]=3.3

rr[4]=8.6
bb[4]=4.6

rr[5]=4.3
bb[5]=5.7

rr[6]=5.6

rr[7]=7.5

rr=3.3

rr[9]=4.6

rr[10]=5.7


try checking on subset of column directly :- Book1_B -b 6 -e 9
limit.size=10



In each case the limit.size is retuning the size of the column which is correct for the X column
The loop clearly show that there are the right amount of elements for each result and that the values in this case limit.ymin is correct, yet limit.size seems wrong.

Also limit.imin is the index of worksheet not the dataset on which the limit was performed.


They were some comments about if this is how this command is meant to operate?

I can work my way around this but I cam upon this when coding and wondered if this was correct.

thanks
Andrew

PS: sorry about the 8ball smiley

Edited by - andrewdsto on 07/24/2013 04:53:27 AM

greg

USA
1378 Posts

Posted - 07/24/2013 :  5:05:30 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
If you look at the defined BB range ( execute list a in the Script Window to see ranges ) you should see:
BB [Book1]Sheet1!2[6]:1[10]
which means range BB covers row 6 of column 2 to row 10 of column 1 or two columns by 5 rows which should have a size of 10 cells.

Complex ranges like that may or may not work with all commands or X-Functions and I was a bit surprised to see it work with the limit command.

I am not surprised that when you reference this range by row you only get the column 2 values. If we defined the range this way:
range BB [Book1]Sheet1!1[6]:2[10]
then bb[row] would return column 1 values. But you should be aware that such mixed column ranges may be problematic and should probably be avoided. For example, these notations work to define ranges:
range bb = 2[10]:1[6]
range bb = 1[10]:2[6]
but trying to use those ranges will generally fail to return anything useful. (Even less useful or failing completely in earlier versions.)

This notation:
limit Book1_B -b 6 -e 9;
is simply not supported.
You could do:
set Book1_B -b 6;
set Book1_B -e 9;
limit Book1_B;
and that will work correctly.

Also note that ranges can report their own size:
range bb = 1[6:10];
bb.GetSize()=;
will return 5, but that 'mixed' range like
range bb = 1[6]:2[10];
bb.GetSize()=;
also returns 5.

Best advice: stay away from defining a range that crosses columns unless you know a command or X-Function supports it.
Go to Top of Page

andrewdsto

Australia
Posts

Posted - 07/24/2013 :  9:08:44 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi,

thanks for the help, however
The first one was a typing error when trying to arrange the code i wasn't trying to cross columns. for the example

a simple version would read something like

win -a book1;
range rr = col(2);
limit rr;
ls=limit.size;

range bb = 2[$(ls/2)]:2[$(ls)];
limit bb;
limit.ymin=;
limit.imin=;
limit.size=;


returning

limit.ymin=3.3
limit.imin=8
limit.size=10

so still the same error, when acting only on column 2

list a;
Session:
1 BB [Book1]Sheet1!2[5]:2[10]
2 PI 3.1415926535898
3 RR [Book1]Sheet1!col(2)


so bb is telling me its using only indexes from 5 to 10 on column 2
but limit.size is still returning 10 elements.


Also, the command you say is not supported, is a direct copy from the labtalk help file under limit.

see below
[quote]

The following script finds the limits for data1_b from index number 10 to index number 30, inclusive. The properties contain information for this range only.

limit data1_b -b 10 -e 30;

[end quote]

yes I can work around this as I said, I just think this is not quite working like it should.


I do like your set command solution which I didn't think of.


Again thanks
Andrew

PS: I hope you are wrong abut that command not being supported (or supported anymore) I have a lot of old code that uses it and it used to work.

Edited by - andrewdsto on 07/24/2013 9:47:23 PM
Go to Top of Page

greg

USA
1378 Posts

Posted - 07/26/2013 :  5:15:19 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
When I saw the incorrect size, I assumed the long form with -b -e was not supported. I stand corrected, size is wrong in both cases:

limit Book1_B -b 5 -e 10;
limit.size=;
range bb = [Book1]1!2[5:10];
limit bb;
limit.size=;

Both yield 10.

The limit command is very old and I am not sure what the intent of the size property was. Possibly it simply meant the size of the dataset and has nothing to do with the size of the range.

If you need size in that sense, I guess you will have to use:

limit Book1_B -b 5 -e 10;
10 - 5 + 1 =;
range bb = [Book1]1!2[5:10];
bb.GetSize()=;
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