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

2 ビュー (過去 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 Center および File ExchangeInteractive Control and Callbacks についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by