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
 range subset declaration not working

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
jmajors Posted - 07/15/2011 : 3:21:26 PM
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.
11   L A T E S T    R E P L I E S    (Newest First)
lkb0221 Posted - 02/03/2014 : 10:04:16 AM
Hi, Bharat

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

Zheng
OriginLab
greg Posted - 01/14/2014 : 4:59:15 PM
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.
AlexD2 Posted - 01/14/2014 : 08:54:02 AM
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
AmandaLu Posted - 01/14/2014 : 04:04:42 AM
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
AlexD2 Posted - 01/10/2014 : 1:00:06 PM
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
greg Posted - 12/03/2013 : 3:53:43 PM
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];
}
thiago.maf Posted - 12/03/2013 : 10:15:57 AM
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.
greg Posted - 12/02/2013 : 3:50:01 PM
Without details on how you are using the range it is difficult to determine what the problem is.
thiago.maf Posted - 12/02/2013 : 2:54:26 PM
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
jmajors Posted - 07/15/2011 : 5:58:03 PM
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.
Laurie Posted - 07/15/2011 : 5:52:55 PM
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

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