How do I pass a value out of a GUI when button is pressed? The value must be available to another m file
이전 댓글 표시
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
채택된 답변
추가 답변 (2개)
Image Analyst
2013년 5월 26일
1 개 추천
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
댓글 수: 7
Brian
2013년 5월 26일
Image Analyst
2013년 5월 26일
The key line in the FAQ that you should be concerned with is this: "To have GUI1 control GUI2 when GUI2 is already running, you can use the assignin() function." Did you try to use assignin()? It doesn't look like it.
Brian
2013년 6월 21일
Jan
2013년 6월 21일
"assignin(test_3, 'BND_CDN', BND_CDN)" should fail, because "test_3" will most likely not reply one of the two allowed strings 'base' or 'caller' - look into the documentation to find out more: doc assignin.
Assigning variables remotely and magically using ASSIGNIN or EVALIN increases the complexity of a program and decreases the processing speed. So it is recommended to avoid it strictly, especially for beginners. And to be absolutely clear in this point: Don't do this!
Brian
2013년 6월 22일
Brian
2013년 6월 25일
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.
카테고리
도움말 센터 및 File Exchange에서 COM Component Integration에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!