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
 plot graph origin6.1

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
joss31 Posted - 04/17/2014 : 05:36:04 AM
Hi everybody,

I started to use Labtalk on Origin 6.1 some weeks ago. And I need some help again. Thanks to other topic and information on internet I can import multiple ASCII, I can post them in different workbook i can take information from the header.

But now I need to take my workbook and plot it in a graph with in x col(3) and in y col(2).

My code looks like that :

type -a; //open the Script window
getfile -m *.*; // prompt for multiple files
worksheet -a 1; //add a Ycolumn & named it allstrtt like "allstarttime"
worksheet -t 3 4; //change the 3rd column in Xcolumn

double TTIME0 = 0; //create a numeric double precision variable
double TTIME1 = 0; //create a numeric double precision variable
double TTIME2 = 0; //create a numeric double precision variable




for (ii = 1; ii <= count; ii ++)
{
getfile -g ii; // get the iith file into %A
open -w %A; // This IMPORTS that file
hfile=file.open(%A); // This OPENS the file for processing


// Using substitution notation, get the second line of that text:
%A = %[%Z,@2];
// Then you can get the part after the space:
%B = %[%A,>' ']; // This is the triggertime value as a string

//If you need each of the time elements as numeric
ttHours = %[%B,1:2]; // characters 1 and 2
ttMinutes = %[%B,4:5]; // characters 4 and 5
ttSeconds = %[%B,7:%[%B]]; // characters 7 to the length of %B
Triggertime = (ttHours /24) *86400 + (ttMinutes /1440)*86400 + ttSeconds; //the Triggertime is in seconds


if (ii <= (count-(count-1)))
{
TTIME0 = Triggertime; //the value of the first triggertime is saving in TTIME0
TTIME1 = 0;
TTIME2 = 0;
col(3)=%(%H,1)+TTIME2;

}
else
{
TTIME0 = TTIME0; //save the value of TTIME0 during all the treatment
TTIME1 = Triggertime; // save the triggertime of "µcoup'n'" in TTIME1
if ($(TTIME0) != $(TTIME1)) //Compare the value of TTIME0 & TTIME1
{
TTIME2 = TTIME1-TTIME0; //TTIME2 is the difference between TTIME1 & TTIME0
TTIME0 = TTIME0; //save the value of TTIME0 during all the treatment
col(3)=%(%H,1)+TTIME2;

}

col(3)=%(%H,1)+TTIME2;
};
if (ii < count)
{
worksheet -d µcoup $(ii); //Duplicate the active workbook into a new workbook named µcoup$(ii)

col(3)=0;

};
else
{
};
};



So, if somebody can help me for the second time, it could be great but dont forget, I repeat I use an old version of origin (6.1) .

Thank you for you're attention.
11   L A T E S T    R E P L I E S    (Newest First)
joss31 Posted - 05/05/2014 : 05:28:28 AM
So this is my code
doc -s;
doc -n;
getfile -m *.*; // Prompt for multiple files

for (ii = 1; ii <= count; ii ++)
{
getfile -g ii; // Get the iith file into %A
open -w %A; // This IMPORTS that file
hfile=file.open(%A); // This OPENS the file for processing
%P =HEAP%[%A, 50:53]%[%A, 74:76];// Take the value of the heap and the number of the block store it in %P variable
worksheet -c ALLSTRTIME; // Create new Ycolumn named ALLSTRTIME
worksheet -c VALUE;
worksheet -t 3 4; // Change the 3rd Ycolumn(ALLSTRTIME) in Xcolumn

%A = %[%Z,@2];//Using substitution notation, get the second line of that text
//Then you can get the part after the newtab
%B = %[%A,>' ']; // This is the triggertime value as a string

//If you need each of the time elements as numeric
ttHours = %[%B,1:2]; // Characters 1 and 2
ttMinutes = %[%B,4:5]; // Characters 4 and 5
ttSeconds = %[%B,7:%[%B]]; // Characters 7 to the length of %B
Triggertime = (ttHours /24) *86400 + (ttMinutes /1440)*86400 + ttSeconds; // The Triggertime is in seconds
if (ii <= (count-(count-1)))
{
TTIME0 = Triggertime; // The value of the first triggertime is saving in TTIME0
TTIME1 = 0;// Initialize the TTIME1
TTIME2 = 0;
col(3)=%(%H,1)+TTIME2;// Add the TTIME2 & "starttime" column of the worksheet col(3)=col(1) in this case
col(4)=col(2);
win -r %H %P;// Rename the title of the worsheet by %P
%M = %H; // Remember worksheet name and its columns(X1,X2,Y1,Y2)

win -t plot scatter;// Create a graph
%N = %H; // Remember graph name
win -t plot scatter;
%O = %H;
}
else
{
TTIME0 = TTIME0;// Save the value of TTIME0 during all the treatment
TTIME1 = Triggertime;// Save the triggertime of "µcoup'n'" in TTIME1
if ($(TTIME0) != $(TTIME1))// Compare the value of TTIME0 & TTIME1
{
TTIME2 = TTIME1-TTIME0;// TTIME2 is the difference between TTIME1 & TTIME0
TTIME0 = TTIME0;
col(3)=%(%H,1)+TTIME2;// Add the TTIME2 & "starttime" column of the worksheet
col(4)=col(2);
win -r %H %P;
%M = %H;
%Q = %H;

}
col(3)=%(%H,1)+TTIME2;
col(4)=col(2);
win -r %H %P;
%M = %H;
%Q = %H;
};

win -a %N;// Active the graph name save in %N
layer.plotxy(%M_ALLSTRTIME,%M_VALUE);// Plot the value of column ALLSTRTIME VALUE from the worsheet name save in %M
layer -a;// Rescale the axis
set %M_VALUE -c $(ii); // Set active plot to color ii

if (ii >(count-(count-1)))
{
win -a %O;
layer.plotxy(%Q_STARTTIME,%Q_VALUE);
layer -a;
set %Q_VALUE -c $(ii)-1;
}


if (ii < count)
{
window -t data; //create a newworksheet
};
};

win -a %N;// Active the graph name save in %N
label -xb Time(sec); // Rename axis x "Time(sec)"
label -yl Voltage(mV);// Rename axis y "Voltage(mV)"

win -a %O;
label -xb Time(sec); // Rename axis x "Time(sec)"
label -yl Voltage(mV);// Rename axis y "Voltage(mV)"


So I import ascii data, I do calcul with value and I plot it in a graph with different color for each curve. Carefull there is just 24 color in labtalk. I search for change the "form" of the curve when all the color were plot

Thank you for everything Greg.
joss31 Posted - 05/02/2014 : 09:44:55 AM
ok thanks I've just find this command I'me going to use it.
And now everything is good so thank you so much greg.
greg Posted - 05/02/2014 : 08:38:03 AM
Look at the SET command in LabTalk Help:
set %C -c 2; // Set active plot to red
set data3_c -c 4; // set dataplot data3_c to blue

FYI: Your version does not have variable declaration, so:
double TTIME0 = 0;
does not work.
This:
TTIME0 = Triggertime;
is what actually creates the variable.
joss31 Posted - 05/02/2014 : 07:52:09 AM
Thanks it works good! well done !

I use it like that but is it possible to change the color of the curve with an other methods?
(for each curve that I add on this layer I plot this curve in a new color)

doc -s;
doc -n;
getfile -m *.*; // prompt for multiple files


double TTIME0 = 0; //create a numeric double precision variable
double TTIME1 = 0; //create a numeric double precision variable
double TTIME2 = 0; //create a numeric double precision variable

for (ii = 1; ii <= count; ii ++)
{
getfile -g ii; // get the iith file into %A
open -w %A; // This IMPORTS that file
%P =HEAP%[%A, 50:53]%[%A, 74:76];
worksheet -c ALLSTRTIME;
worksheet -c VALUE;
worksheet -t 3 4; //change the 3rd column in Xcolumn

//Using substitution notation, get the second line of that text:
%A = %[%Z,@2];
//Then you can get the part after the space:
%B = %[%A,>' ']; // This is the triggertime value as a string

//If you need each of the time elements as numeric
ttHours = %[%B,1:2]; // characters 1 and 2
ttMinutes = %[%B,4:5]; // characters 4 and 5
ttSeconds = %[%B,7:%[%B]]; // characters 7 to the length of %B
Triggertime = (ttHours /24) *86400 + (ttMinutes /1440)*86400 + ttSeconds; //the Triggertime is in seconds


if (ii <= (count-(count-1)))
{
TTIME0 = Triggertime; //the value of the first triggertime is saving in TTIME0
TTIME1 = 0;
TTIME2 = 0;
col(3)=%(%H,1)+TTIME2;
col(4)=col(2);
win -r %H %P;
%M = %H;
//A graph
win -t plot scatter;
%N = %H; // remember graph name;
}
else
{
TTIME0 = TTIME0; //save the value of TTIME0 during all the treatment
TTIME1 = Triggertime; // save the triggertime of "µcoup'n'" in TTIME1
if ($(TTIME0) != $(TTIME1)) //Compare the value of TTIME0 & TTIME1
{
TTIME2 = TTIME1-TTIME0; //TTIME2 is the difference between TTIME1 & TTIME0
TTIME0 = TTIME0; //save the value of TTIME0 during all the treatment
col(3)=%(%H,1)+TTIME2;
col(4)=col(2);
win -r %H %P;
%M = %H;

}
col(4)=col(2);
col(3)=%(%H,1)+TTIME2;
win -r %H %P;
%M = %H;
};
win -a %N;
layer.plotxy(%M_ALLSTRTIME,%M_VALUE);

layer -a;
//
if (ii < count)
{
//worksheet -d ucoup $(ii); //Duplicate the active workbook into a new workbook named µcoup$(ii)
window -t data;
};
else
{
};
};
greg Posted - 04/28/2014 : 4:09:16 PM
// WARNING! Destructive script
doc -s;
doc -n;

// Some data
col(1)=uniform(20);
wo -a 1;
col(3)=data(1,20);
col(2)=sin(pi*18*col(3)/180);
%M = %H; // Remember first worksheet;

// A graph
win -t plot scatter;
%N = %H; // remember graph name;

// More data
win -t data;
wo -a 1;
col(3)=data(0,22,2.2);
col(2)=cos(pi*15*col(3)/180);
%O = %H; // remember this data

// Make the graph active
win -a %N;
layer.plotxy(%M_C,%M_B);
layer.plotxy(%O_C,%O_B);
set %O_B -c 2;
layer -a;
joss31 Posted - 04/28/2014 : 10:47:33 AM
thanks but for create my empty graph window i use that:

window -e Graph1;


I put your code after but it doesn't work I don't succed have you got an example with this methods?

window -o Graph1
{
layer.plotxy(ucoup1_C,ucoup1_B); // plot ucoup1C as X and ucoup1_B as Y
layer -a; // Rescale the graph
};
greg Posted - 04/25/2014 : 4:31:00 PM
Your version does not have a plotxy X-Function (it doesn't have any X-Functions), but it does have the plotxy method of the layer object.
As an example, if you already have an empty graph named Graph1, you can add curves like this:
win -o Graph1
{
layer.plotxy(ucoup1_C,ucoup1_B); // plot ucoup1C as X and ucoup1_B as Y
layer.plotxy(ucoup2_C,ucoup2_B); // plot ucoup2C as X and ucoup2_B as Y
layer -a; // Rescale the graph
}
joss31 Posted - 04/23/2014 : 09:44:26 AM
Hi,
I've been tried your example but it's not exactly that I want.

see on the picture black's column's, that what I need for my graph. How can I put the in a graph? I tried the plotxy function but doesn't work. Have you got any ideas?



greg Posted - 04/18/2014 : 11:25:40 AM
Your version has all kinds of window management headaches which I won't go into, but
IF you have created a plot window like:

window -t plot line MyGraph;

THEN when your imported worksheet is active you can get the Short Name of the last column with:

%A = wcol(wks.ncols);

AND add that to your graph:

window -o MyGraph {
layer -i %A;
layer -a;
}

Another approach:
AFTER all your worksheets have been loaded, execute:

window -t plot LINE MyGraph;
document -e W {
%A = wcol(wks.ncols);
window -o MyGraph {
layer -i %A;
}
}
layer -a;

Check the LabTalk Help file for "window", "document" and "layer" commands, the "wcol" function and the "wks" object if you have any questions about the above script.
joss31 Posted - 04/18/2014 : 05:29:01 AM
I use "worksheet -p" because I didn't found another solution for plotting a graph.
But if you have a better solution I'll don't say no.
I want just plot the 2 last column of different woorksheet in the same graph it's possible, isn't it?
greg Posted - 04/17/2014 : 10:38:36 AM
I don't pretend to understand the logic of what you are doing, but if you want to use
worksheet -p
then you should select your data before running that. Also, "2" is not a valid PlotID and "template" should be a valid template name - like "SCATTER". Both problems seem to be ignored by 6.1.

Here is how to plot all the data in the worksheet:
worksheet -s 0 0 0 0;
worksheet -p 201 scatter;

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