Problem with GUI plotting

I run a GUI where i enter values through edit boxes in order to take a plot, for example a simple line between A and B (i enter their coordinates through the boxes)
The function that plot the line is called from a push button.
I enter the A,B coordinates, press the button and get the plot with the line.
If, while still running the GUI, i enter a different value for A or B and press the button i get two lines in the plot.
What can i do so that when i press the button for a second time the first plot gets erased and the second plot is displayed alone?

 채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2013년 9월 22일

0 개 추천

add
hold(handles.axes1, 'on')

댓글 수: 3

Dimitris Arapidis
Dimitris Arapidis 2013년 9월 22일
it didn't work.
I have an axes, 2 edit boxes x1,x2 and the run button.
I use the following code on the run callback:
x1 = str2double(get(handles.x1,'String'));
x2 = str2double(get(handles.x2,'String'));
y1=1;
y2=2;
hold(handles.axes1, 'on')
plot([x1 x2],[y1 y2],'r')
guidata(hObject,handles);
strings are taged properly because i get the plots but they still overlap when i change x1,x2.
I misunderstood your question
cla(handles.axes1)
plot....
Dimitris Arapidis
Dimitris Arapidis 2013년 9월 22일
thank you

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

추가 답변 (1개)

Image Analyst
Image Analyst 2013년 9월 22일

0 개 추천

Put
cla reset
before you plot the new line. Or else
hold off
would probably work too.

카테고리

도움말 센터File Exchange에서 Programming에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by