![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/726459/image.png)
How do I vary the colour of a continuous graph in App Designer
7 次查看(过去 30 天)
显示 更早的评论
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.
0 个评论
采纳的回答
Pavan Guntha
2021-9-1
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.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/726459/image.png)
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!
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Specifying Target for Graphics Output 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!