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
 range subset declaration not working
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

jmajors

2 Posts

Posted - 07/15/2011 :  3:21:26 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
Operating System:windows 7

I am trying to get a subset of rows from a column using a new range:

range r=col(C)[4:20]

regardless of initial number this will only return to me rows 1 to 20. more specifically I need this to work:

range r1=Col(C);
pind=1; //index of points for the final curve

for (i=1; i< r1.GetSize(); i++){

range r3 =Col(C)[i-3:i+3];
//rangesize=r3.GetSize(); //(debugging)
//type"$(rangesize)";

tempmax= max(r3);

if(tempmax==Col(C)[i]){
Col(toplotx)[pind]$=$(Col(A)[i]);
Col(toploty)[pind]$=$(Col(c)[i]);
pind++;

}
}

something about the row declaration in general does not work with ranges, what am i doing wrong?? thank you.

Laurie

USA
404 Posts

Posted - 07/15/2011 :  5:52:55 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Try this:

range r3 =Col(b)[$(i-3):$(i+3)];

Note: getsize( ) will not return the correct number of elements...in Origin 8 it did not work for a subrange like that

OriginLab Technical Support
Go to Top of Page

jmajors

2 Posts

Posted - 07/15/2011 :  5:58:03 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
thank you, i did try that, but it doesn't seem to be the variable aspect that is giving the problem.

range r3=col(C)[5:10]

doesn't work either. It will always start from the first row, giving me rows 1-10 in this case.
Go to Top of Page

thiago.maf

22 Posts

Posted - 12/02/2013 :  2:54:26 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Same problem here.
Can't define a subrange in 'before formula script'; always returning the full range.

I'm following this: http://wiki.originlab.com/~originla/ltwiki/index.php?title=LabTalk:Range_Notation&rdfrom=http%3A%2F%2Fwiki.originlab.com%2F%7Eoriginla%2Fwiki%2Findex.php%3Ftitle%3DLabTalk%3ARange_Notation%26redirect%3Dno#Worksheet_Data
Go to Top of Page

greg

USA
1379 Posts

Posted - 12/02/2013 :  3:50:01 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Without details on how you are using the range it is difficult to determine what the problem is.
Go to Top of Page

thiago.maf

22 Posts

Posted - 12/03/2013 :  10:15:57 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
The same problem described before:

"range r3=col(C)[5:10]

doesn't work either. It will always start from the first row, giving me rows 1-10 in this case."

In my case, I was trying to do two things: 1) copy part of a column to a new column; 2) use part of a column in a dataset.
Go to Top of Page

greg

USA
1379 Posts

Posted - 12/03/2013 :  3:53:43 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Still not enough detail, plus you have not mentioned your version.
This code:

range r3 = col(C)[5:10];
col(D) = r3;

works if you have Origin 8.1 or greater, but not Origin 8.0.

It sounds like you have version 8 so you will need to use loops when dealing with sub-ranges:

range r3 = col(C);
loop(ii,5,10)
{
col(D)[ii-5] = r3[ii]; // or col(D)[ii] = r3[ii];
}
Go to Top of Page

AlexD2

France
19 Posts

Posted - 01/10/2014 :  1:00:06 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
I encounter the same problem.

I have OriginPro version 9.1 on Windows7 32bit.

If I enter the following in a Command Window:
>>range aa = 1!col(1)[3:5]

aa resolves in the full column 1:
>>type "$(aa)"
1 2 3 4 5 6 7 8

If I use the -v option, it seems to solve the problem:
>>range -v aa = 1!col(1)[3:5]
>>type "$(aa)"
3 4 5

But this should not be the default behavior.

Also, I actually encountered another related problem.
In the Help:LabTalk/Range_Notation, it is given the following syntax:

/* Defines a range variable for col(2) of 1st and 2nd sheet,
rows 3-5, and runs the stats XF on that range: */
>> range aa = (1,2)!col(2)[3:5]; stats aa;

If I perform the range definition above (making sure that I have two sheets in the active workbook with data in the 2nd columns) the assignment fails:

* Without the -v option I get:
>>range aa = (1,2)!col(1)[3:5]
>>type "$(aa)"
1 2 3 4 5 6 7 8

* With the -v option I get:
>>range -v aa = (1,2)!col(1)[3:5]
>>type "$(aa)"
--

As for some supplementary tests:
>>range aa = (1,2)!col(1)[3:5]; type %(aa); type $(aa)
[Book1](1,2)!col(1)[3:5]
1 2 3 4 5 6 7 8
>>aa = {101:106}
Result:
101, 102 and 103 are assigned to rows 3, 4 and 5 of column 1 of sheet 1, but nothing happens in column 1 of sheet 2

And with the -v option:
>>range -v aa = (1,2)!col(1)[3:5]; type %(aa); type $(aa)
[Book1](1,2)!col(1)[3:5]
0 0 0 0 0 0
>>aa = {101:106}
Result:
Nothing happened to the cells of the columns, but I obtain this:
>>type "$(aa)"
101 102 103 104 105 106

I am very lost.
Is this a bug or am I overlooking something here?

Thanks for your help.

AlexD2
Go to Top of Page

AmandaLu

439 Posts

Posted - 01/14/2014 :  04:04:42 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi AlexD2,

range can be used to define a sub-range. Please try

range aa = 1!col(1)[3:5];
max(ea)=;

it will return the maximum of row 3 to 5 in the first column of first sheet. But there is indeed a bug in type command. type always outputs the full range. We have submitted a JIRA (ORG-10451) and will try to fix it in the future version. Sorry for the confusion it caused.
range -v cannot use to define a non- contiguous range. So it cannot be used to declare subrange in two different sheets. If you declare multiple subrange using range, manipulating on Range Data only take effect on the first sub range specified in the range declaration.

Sincerely,
Amanda
OriginLab Technical Service

Edited by - AmandaLu on 01/14/2014 05:03:08 AM
Go to Top of Page

AlexD2

France
19 Posts

Posted - 01/14/2014 :  08:54:02 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Thank you very much for your answer Amanda.

I must have had a variable conflict in my previous Origin session since now the non-contiguous range declaration and stats command run fine.

Thank you also for the clarification about the -v option.

However, now that I repeat the tests, it seems that I the range -v declaration works partially?
At least I can then perform the stats analysis. But indeed, assigning values do not work consistently (when assigning a non-contiguous range, some values are assigned while others are not).

It would maybe be helpful if such operations were not allowed at all and if they were outputting some explanatory error message such as:
"[Operation] cannot be performed with [variable type]"

Thanks again for your answer.

AlexD2
Go to Top of Page

greg

USA
1379 Posts

Posted - 01/14/2014 :  4:59:15 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
ty $(RangeVariable);
is not reliable and probably should produce a command error or warning of some sort.

ty %(RangeVariable);
is fine and using %(RangeVariable) to construct more complex range variables is a standard technique.

Range variables constructed with or without the -v option should not be treated as if they were datasets (vectors). They are really meant to be passed to X Functions as arguments and those X Functions have to be designed to accept the particular type of range. A XF that accepts only a one column range will fail if passed a range that includes multiple columns.
Go to Top of Page

lkb0221

China
497 Posts

Posted - 02/03/2014 :  10:04:16 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi, Bharat

As Grag explained, this will work if you have Origin 8.1 or greater.

Zheng
OriginLab
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