How do I pass a value out of a GUI when button is pressed? The value must be available to another m file
2 ビュー (過去 30 日間)
古いコメントを表示
Hello,
I am making a GUI which adds rows to a matrix in one part. I want the matrix to be available to another m-file when I press another button (export). I've been looking at this for two weeks and can't figure it out. What is the syntax to make this matrix available to another function? eg x = function (y, exported_matrix). The normal [export_matrix] =Callback_pushbutton(....) doesn't work for GUI's. Can someone explain this? Sorry, this is probably basic but I can't see by any examples how this would work with my own GUI.
Thanks,
Brian
0 件のコメント
採用された回答
Brian
2013 年 6 月 25 日
1 件のコメント
Image Analyst
2013 年 6 月 25 日
You had said "I have tried global, ..., I have been at this for three days, I'm not getting it. " I guess you eventually got it right.
その他の回答 (2 件)
Image Analyst
2013 年 5 月 26 日
Did you ever stumble upon the FAQ: http://matlab.wikia.com/wiki/FAQ#How_can_I_share_data_between_callback_functions_in_my_GUI.28s.29.3F
Jan
2013 年 6 月 21 日
編集済み: Jan
2013 年 6 月 21 日
Assume your GUI has the tag-property 'MyGUI' (a more meaningful tag is recommended...). Then the store the matrix in the handles struct inside the GUI:
handles.matrix = rand(10, 10); % Or how ever you define the elements
guidata(hObject, handles); % 1st argument: handle of the current object
Now obtain the matrix from your external M-file:
function theExternalFunction
guiHandle = findobj(allchild(0), 'flat', 'tag', 'MyGUI');
guiHandles = guidata(guiHandle);
matrix = guiHandles.matrix;
...
guidata() is a wrapper for setappdata() and getappdata(). Some exceptions should be caught by tests, e.g. if the guiHandle cannot be found because the GUI has been closed before, etc.
参考
カテゴリ
Help Center および File Exchange で Interactive Control and Callbacks についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!