How to stop overwriting the old values from a loop inside a GUI?

조회 수: 1 (최근 30일)
Alonso
Alonso 2015년 11월 4일
편집: Alonso 2015년 11월 4일
Hello. I've taken a part from an old, unanswered question (<http://www.mathworks.com/matlabcentral/answers/39533-save-continously>) and made some modifications, but I'm pursuing the same goal. I'm working in a GUI, and I believe it's something quite simple, so here is the matter: There's a figure with 2 edit boxes, where the user enters the X & Y coordinates, and a button that saves them in a vector "Z".
This action has to be repeated n-times (2 times in this case) and saved in a vector Z1,Z2,..Zn, besides the edit boxes have to be cleared every time a new pair of coordinates wants to be written. The problem is that, while the user enters new values, they get overwritten and the result are the last entered values and some NaN's. The code from the pushbutton is attached below. I think the problem is after the red line, but I don't know how to fix it, I've already tried "uiwait", "waitforbuttonpress" and other methods to stop the process and be able to enter the new values. Besides, I would like the figure to close once the iterations are complete. Thank you for your kind cooperation.

답변 (1개)

TastyPastry
TastyPastry 2015년 11월 4일
I'd put k and ng as handles on the dialog box figure.
myGUI.k = 1;
myGUI.ng = 3;
Then,
function myCallback(varargin)
fig = gcf;
handles = guidata(fig);
if handles.k>handles.ng
return;
end
%save data as .mat
handles.k = handles.k+1;
guidata(fig,handles);
end
  댓글 수: 1
Alonso
Alonso 2015년 11월 4일
I'm sorry, but where am I supposed to write those in the .m file? Inside the function pushbutton1_Callback(hObject, eventdata, handles)?

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

카테고리

Help CenterFile Exchange에서 Migrate GUIDE Apps에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by