Keeping data w/i a single function of a MATLAB GUI

조회 수: 3 (최근 30일)
aaron pung
aaron pung 2014년 6월 26일
댓글: aaron pung 2014년 6월 26일
Greetings, my question is as follows: I'm trying to make a function that will store an amount of data w/i a matrix, within a MATLAB GUI. The idea is that the user presses a button ("Advance"), which increases the iteration number. The iteration number is shown in the textbox. I'd like to maintain a matrix (h.h) that keeps track of the number of iterations. So, for five iterations, I would ideally get:
h.h = [1 1 1 1 1; 2 2 2 2 2; 3 3 3 3 3; 4 4 4 4 4; 5 5 5 5 5];
The problem I'm getting, is that during the 2nd iteration, the data from the 1st iteration will be deleted. So, the data that I see is, instead,
h.h = [0 0 0 0 0; 0 0 0 0 0; 0 0 0 0 0; 0 0 0 0 0; 5 5 5 5 5];
My script is as follows: . . .
if true
function varargout = updater(varargin)
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @updater_OpeningFcn, ...
'gui_OutputFcn', @updater_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:}); else gui_mainfcn(gui_State, varargin{:}); end % End initialization code - DO NOT EDIT
function updater_OpeningFcn(hObject, eventdata, handles, varargin)
% Choose default command line output for updater handles.output = hObject;
% Update handles structure guidata(hObject, handles);
function varargout = updater_OutputFcn(hObject, eventdata, handles) % Get default command line output from handles structure varargout{1} = handles.output;
function ITERinput_CreateFcn(hObject, eventdata, handles) if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end
function ITERinput_Callback(hObject, eventdata, handles) coinno = str2num(get(hObject,'String')); if (isempty(coinno)) set(hObject,'String','0') end guidata(hObject, handles);
function ITERbutton_Callback(hObject, eventdata, handles) currentCounterValue = str2double(get(handles.ITERinput, 'String')) newString = sprintf('%d', int32(currentCounterValue +1)); set(handles.ITERinput, 'String', new
if true
% code
endString );
h.h(currentCounterValue,:) = [currentCounterValue currentCounterValue currentCounterValue currentCounterValue currentCounterValue] h.h end
. Thank you! Also, sorry for the below code not coming out as it should have. I'm not sure how much to include from a GUI, but I can send files if needed.
  댓글 수: 1
Sara
Sara 2014년 6월 26일
Please, edit your question, it's impossible to read the code portion.

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

채택된 답변

Sara
Sara 2014년 6월 26일
You need to put h.h into the handles variable:
handles.h.h = .....
and add
guidata(hObject, handles);
at the end of ITERbutton_Callback to save it.
  댓글 수: 1
aaron pung
aaron pung 2014년 6월 26일
Sara, Thank you! I was actually JUST wondering whether or not I'd have to assign it as a handle, since those seem to carry all the data through the functions. Thank you, problem solved!!

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Event Functions에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by