MATLAB Answers

How do I vary the colour of a continuous graph in App Designer

2 views (last 30 days)
I have got 3 sliders in the app designer, and I want to change the colour of the graph based on those values. And, I want to display the graph like a shift register, displaying 100 values at a given time. This is the way I am doing it:
plot(app.UIAxes_Error,error,'color',[Kp/10,0,0]);%Kp varies from 0 to 10
And, I am shifting the 'error' vector like this:
if i==100
error=error(2:end);
else
i=i+1;
end
But, as I am plotting the entire vector again, the colour of the entire graph changes.
I want the colour to change from the point I change the value of the slider, and all previous points on the graph still retaining their colour.

Accepted Answer

Pavan Guntha
Pavan Guntha on 1 Sep 2021
Hi,
You could use 'hold(app.UIAxes_Error, 'on')' version of hold command to plot data on top of data which is already plotted on UIAxes. The following example illustrates this idea. The slider value sets the plot color and upon clicking the 'Plot' button, the UIAxes get refreshed and shows the newly plotted data along the previous data in their respective colors.
The MATLAB App file which illustrates the above example is attached for your reference. For information regarding 'hold', you could have a look at the documentation page: Retain current plot while adding new plots
Hope this helps!

More Answers (0)

Products


Release

R2021a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!