Keeping data w/i a single function of a MATLAB GUI
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
aaron pung
am 26 Jun. 2014
Kommentiert: aaron pung
am 26 Jun. 2014
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 Kommentar
Akzeptierte Antwort
Sara
am 26 Jun. 2014
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.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Data Type Identification finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!