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
 Array of range variables as function input

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
ds755 Posted - 05/20/2020 : 3:51:54 PM
Origin Ver. and Service Release (Select Help-->About Origin): OriginPro 2020 (64-bit) SR1
Operating System: Windows 8.1

Hello,

May I ask please if there is a way to feed an array of range variables, integers, and strings as an input argument of a function?

I have a function that plots things and I want to vary the amount of curves that are plotted (i.e. the input arguments). For example, ideally I'd want the input argument to be an array, with each element consisting of a range variable (curve to be plotted), an integer (layer No), and a string (denoting scatter vs line plot). For example:

(Curve1, 1, L) // line plot
(Curve2, 1, S) // scatter plot
....

So far, I am trying with datasets but it doesn't work. Example:


function PlotStuff (int LayersNo, dataset Curves){
	page.active = 1; // activate Layer No 1
	layer.include(Curves(1));  // plot in the active layer
};

....

dataset Curves = {rId, rIg};
PlotStuff(1, Curves); // This does not work
3   L A T E S T    R E P L I E S    (Newest First)
ds755 Posted - 05/21/2020 : 6:52:17 PM
Hi,

If you set rlin=2 and then have a graph with a label named "Text2", then the 2 will be replaced by --.

Essentially, I'm trying to pass the value of a graphic object inside the function.
YimingChen Posted - 05/21/2020 : 11:05:53 AM
Hi,

You may miss quotation marks for Labelvalues string arry. I tried the script below and it worked.

function test1(StringArray Labelnames, StringArray Labelvalues)
{
	for (int i = 1; i <= 3; i++)
	{
		if (exist(%(LabelNames.GetAt(i)$),16)==16)
		{
			%(LabelNames.GetAt(i)$).text$ = %(Labelvalues.GetAt(i)$);
		}
	}
}

StringArray LabelNames = {"Text2", "Text3", "Text4"};
StringArray Labevalues = {"r\-(lin)=$(rlin) %", "J\-(ch,max,lin)=$(jmaxlin, .1) A/cm\+(2)", "P\-(ch,max,lin)=$(Pmaxlin, .1) W/cm\+(2)"};
test1(LabelNames, Labevalues)


Thanks,
James
ds755 Posted - 05/21/2020 : 05:59:55 AM
I've almost succeeded in coding what I wanted by declaring the column numbers and the layer numbers with datasets and then using the wcol command inside the function to define the range. This is an indirect way of passing an array of range variables inside the function. For example, if I wanted to plot columns 8 and 10 (X-axis is column 1), both in Layer 1:

Layers = {1, 1};
Columns = {8, 10};
PlotSingle(..., Layers, Columns....);


And the function becomes

function PlotSingle (..., dataset Layers, dataset Columns, ....)
{
.....
range rI = [%H]1!wcol(Columns[i]); // range variable
win -a %(uid2name(range2uid(["%(graphname$)"]))$); // activate the graph window
page.active = Layers[i]; // activate Layer i
layer.include(rI);  // plot in the active layer
...
}



OK, now I have a second problem. I'm trying to modify Labels in the graphs via the function as well, so I need to pass the arguments successfully. I'm trying to do this with StringArrays but so far it's not working. For example, the label modification without the function would look like this:

if (exist(Text2,16)==16) Text2.text$ = r\-(lin)=$(rlin) %; // If the label exists, update it

if (exist(Text3,16)==16) Text3.text$ = J\-(ch,max,lin)=$(jmaxlin, .1) A/cm\+(2); // If the label exists, update it

if (exist(Text4,16)==16) Text4.text$ = P\-(ch,max,lin)=$(Pmaxlin, .1) W/cm\+(2); // If the label exists, update it


So basically just look if the labels exist and then update them.

Now for the modified version. The code inside the function looks like this:

function PlotSingle (..., StringArray LabelNames, StringArray LabelValues, ...) // Plot transfer curve
{
int LabelsNo = 3;
if (LabelsNo >= 1){
	loop(i, 1, LabelsNo){
		if (exist(%(LabelNames.GetAt(i)$),16)==16) %(LabelNames.GetAt(i)$).text$ = %(LabelValues.GetAt(i)$); // If the label exists, update it
		};
	};



And I'm calling it like this:

StringArray LabelNames = {"Text2", "Text3", "Text4"};
StringArray LabelValues = {r\-(lin)=$(rlin) %, J\-(ch,max,lin)=$(jmaxlin, .1) A/cm\+(2), P\-(ch,max,lin)=$(Pmaxlin, .1) W/cm\+(2)}; // Problem
PlotSingle(..., LabelNames, LabelValues, ...);


The problem exists in the StringArrays. I cannot pass them in the function. Any ideas as to what the mistake is?

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