Written by Erez Wenger - June 2011
In this post we explain, in images and code-lines, how to easily plot multiple traces.
If you are using a stripchart (see our previous stripchart post here) you might want to show two or more traces at once. This can be very useful as you can avoid using many stripcharts, save space, and do it in an elegant way.
Changing the number of traces on the UIR
- Go to the UIR and edit the stripchart control.
- Click the Traces button.
- Change the number of traces to the desired amount.
- Select style and color for each trace.
- Define an array as large as the amount of traces you want.
- On each time step calculate the value of each trace.
- Use the PlotStripChart command to draw the traces.
double y[2]; //Array for 2 traces
switch (event)
{
case EVENT_TIMER_TICK:
y[0]=sin(Pi()*t); //first trace calculation
y[1]=2.0*sin(Pi()*t+0.5); //second trace calculation
PlotStripChart (panelHandle, PANEL_STRIPCHART, y, 2, 0, 0, VAL_DOUBLE); //plotting the traces
t+=0.01;
break;
}
Great Job, thank you, Lotfi.
ReplyDeletePlease update pictures in your lessons, thank you very much.
ReplyDeleteThanks Hung... there is a bug on the website that corrupts images over time. Will be fixed soon.
ReplyDeleteReally helpful, Thanks a lots!
ReplyDeletesuper !
ReplyDeleteHi! I'm at work browsing your blog from my new iphone!
ReplyDeleteJust wanted to say I love reading your blog and
look forward to all your posts! Carry on the great work!