I am trying to plot graphs of various iterations into the same graph with App Designer. Temps_ON, Temps_OFF,... are columns of a table.
The problem encountered is that it only plots the last value (for i=3 in this case). Any advice on how to manage this ?
while i<4
x=t.Temps_ON(i);
y=zeros(1,x);
y(1) =t.Puissance_ON(i);
x1= t.Temps_OFF(i);
y1=zeros(1,x1);
y1(1) = t.Puissance_OFF(i);
x2=t.Temps_reveil(i);
y2=zeros(1,x2);
y2(1) =t.Puissance_reveil(i);
% Plot modified data
for time=1:x-1
y(time+1)=y(time);
end
for time=1:x1-1
y1(time+1)=y1(time);
end
for time=1:x2-1
y2(time+1)=y2(time);
end
plot(app.UIAxes,(1:x),y,'b',(1+x:x1+x),y1,'b',(x+x1+1:x+x1+x2),y2,'b');
i=i+1;
end

댓글 수: 5

You need to set
hold on
By default, hold is set to "off". That means every new plot command overwrites any previously plotted items. If you set hold to "on", it will 'hold on' to whatever you have already plotted.
In App Designer, you have to specify axes for which hold on will be active.
hold(app.UIAxes, 'on')
Frédéric LE QUILLIO
Frédéric LE QUILLIO 2021년 2월 15일
I have already try hold on and even hold(app.UIAxes,'on'); but it's not efficient since it will plot a new graph each time a value in the table is changed which is not what I want. I want to plot the graph for each line of my table (i is used to increment the number of the line in my table)
Do you have any errors? Try checking these values for each step, maybe they are empty, or they are a single point. Single points are not visible by default, you'll need to specify the marker for those.
(1:x)
y
(1+x:x1+x)
(x+x1+1:x+x1+x2)
y2
Frédéric LE QUILLIO
Frédéric LE QUILLIO 2021년 2월 15일
I don't have any errors. These values work correctly since I can see the good graph for the 3rd value in this case. The problem is the loop I don't understand why the previous graph are not plotted too

댓글을 달려면 로그인하십시오.

답변 (1개)

Nikhil Sonavane
Nikhil Sonavane 2021년 3월 23일

0 개 추천

In my understanding, hold on retains plots in the current axes so that new plots added to the axes do not delete existing plots. It doesn't update the graph when an entry is changed in the table unless you run the code again. You can refer to the documentation of hold for more details about the function.

카테고리

도움말 센터File Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

질문:

2021년 2월 15일

답변:

2021년 3월 23일

Community Treasure Hunt

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

Start Hunting!

Translated by