Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
242 views
in Technique[技术] by (71.8m points)

How do you use "hold on" with MATLAB GUI?

I am working with GUIDE to make a big GUI. I would like to plot two sets of data on the same plot. For regular MATLAB code I would write:

time = 1:10;
data1= (1:10).*2;
data2= (1:10).*3;
figure;
plot(t,data1);
hold on;
plot(t,data2);
hold off;

However, this does not work with the GUI system. With the GUI I am typing:

time = 1:10;
data1= (1:10).*2;
data2= (1:10).*3;
plot(handles.axes1,t,data1);
hold on;
plot(handles.axes1,t,data2);
hold off;

But this does not work. data2 just over writes the previous plot. Any help would be appreciated. Thank you.

SOLUTION:

time = 1:10;
data1= (1:10).*2;
data2= (1:10).*3;
plot(handles.axes1,x,y);
hold(handles.axes1)
plot(handles.axes1,x,z);
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

If this is the only thing you want to plot, just use plot functions without axes handle (they will have the same handle by default):

t = 1:10;
data1= (1:10).*2;
data2= (1:10).*3;
plot(t,data1);
hold on;
plot(t,data2);
hold off;

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...