Incrementing GUIDE variable

6 ビュー (過去 30 日間)
B_Richardson
B_Richardson 2011 年 7 月 19 日
Goodmorning community,
Quick question:
I have 2 variables that I declare in a createfunction in my GUIDE GUI:
handles = guidata(gcf);
if ~isfield(handles, 'MyMatrix');
handles.MyMatrix = zeros(2, 10);
guidata(gcf, handles);
end
handles = guidata(gcf);
if ~isfield(handles, 'increment');
handles.increment = 1;
guidata(gcf, handles);
end
So the idea is to use .increment to index .MyMatrix
%Pushbutton callback%
MyValue = str2double(get(handles.edit2,'String')); %get value
handles.MyMatrix(handles.increment)= MyValue;
handles.inc + 1; %This is what is not working
handles = guidata(gcf);
I have tried handles.inc = handles.inc + 1; as well.
Right now my output after 2 clicks of the push button are:
ans =
29.5744 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
27.5465 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
Instead of
29.5744 27.5465 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
Thanks in advance!!!
  2 件のコメント
Sean de Wolski
Sean de Wolski 2011 年 7 月 19 日
What didn't work about:
"I have tried handles.inc = handles.inc + 1; as well."
That appears to be correct to me. Did it throw an error?
You could also look at using persistent variables
B_Richardson
B_Richardson 2011 年 7 月 19 日
Yes that did work. Actually what the problem was
handles = guidata(gcf);
should have been
guidata(gcf, handles)
thanks!

サインインしてコメントする。

採用された回答

Walter Roberson
Walter Roberson 2011 年 7 月 19 日
In your callback, instead of doing handles = guidata(gcf); after the increment of handles.inc, do guidata(gcf, handles) as you want to write out the new value.
  1 件のコメント
B_Richardson
B_Richardson 2011 年 7 月 19 日
that did it!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMigrate GUIDE Apps についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by