How to load a variable into the workspace not as a structure into a GUI?

조회 수: 23 (최근 30일)
Adriano
Adriano 2017년 11월 27일
댓글: Stephen23 2017년 11월 27일
Hi everybody, I'm developing a GUI and I need to load a variable into the workspace. I'm using the "assignin" function but it generates a struct variable. This is my code:
function popupmenu1_callback(hObject, eventdata, handles)
asset = 'XYZ';
assignin('base',asset, load('XYZ.mat'));
end
the output is XYZ struct variable. Thus, to get my data I must do XYZ.XYZ . How can avoid that and to get directly the XYZ variable (not like a struct)? Many thanks!
  댓글 수: 1
Stephen23
Stephen23 2017년 11월 27일
As Jan Simon mentioned, making variables magically appear in other workspaces is not recommended. Doing so will make your code slow, complex, buggy, and hard to debug. Read this to know why:

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

채택된 답변

Jan
Jan 2017년 11월 27일
Remember, that the remote controlled creation of variables in another workspace is a bad programming style. I would avoid this strictly, but store the data inside the figure and use it from there.
But if you really want to do this:
asset = 'XYZ';
Data = load('XYZ.mat');
assignin('base', asset, Data.(asset));

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Software Development Tools에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by