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?

답변 (1개)

Walter Roberson
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.
  댓글 수: 2
Joseph Mazzella
Joseph Mazzella 2018년 11월 29일
I apologize I am refrencing sending the variables to the base workspace. The idea is to have different numbers be loaded for one variable name based upon the dropdown I want. What is the proper way to load a .mat and its variables by a callback and then share those with the base workspace
Walter Roberson
Walter Roberson 2018년 11월 29일
Example:
datastruct = load(AppropriateFileName);
assignin('base', 'CheeseProductionPerBee', datastruct.Chz_per_b);

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile 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!

Translated by