How can I have a pushbutton load the variables in a .mat file into the matlab workspace?
조회 수: 5 (최근 30일)
이전 댓글 표시
I have a drop down menu with various selections and based on the drop down I have a switch case to perform a load call for a .mat file however it goes through the function but does not out any variables to my worspace. Is there a way to have the pushbutton load variables from different files to the workspace based upon the selection in the dropdown menu above it?
댓글 수: 0
답변 (1개)
Walter Roberson
2018년 11월 29일
Your callback is a function, and variables you create there get placed in the workspace of that callback function unless you specifically move them elsewhere.
You cannot really talk about "my workspace" in GUIs. There is the base workspace, and there is the global workspace. You might have a workspace of a function executing as a result of creating the GUI, but it is more typical to have that function return and to work entirely by callbacks (except when creating .exe in which case you still rely upon callbacks but you wait for the work to be done and then close down the GUI.) Most of the time, there is the workspace of the function that is currently executing and you can trace back in the call chain to a callback function that MATLAB executed when an event occured. But you that is about as far back as you can go; there is no "there" there, no workspace for the variables to be put into.
Therefore you need to share values or stash variables.
http://matlab.wikia.com/wiki/FAQ#How_can_I_share_data_between_callback_functions_in_my_GUI.28s.29.3F
댓글 수: 2
Walter Roberson
2018년 11월 29일
Example:
datastruct = load(AppropriateFileName);
assignin('base', 'CheeseProductionPerBee', datastruct.Chz_per_b);
참고 항목
카테고리
Help Center 및 File Exchange에서 Scope Variables and Generate Names에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!