フィルターのクリア

I am running a .m file from the GUI .. the .m file has many variables which will be saved in workspace when i run without GUI but when i run via GUI workspace is empty .. why

2 ビュー (過去 30 日間)
m s
m s 2012 年 5 月 23 日
コメント済み: Walter Roberson 2020 年 3 月 5 日
I am running a .m file from the GUI .. the .m file has many variables which will be saved in workspace when i run without GUI and these variables will be used by other .m files. when i drag and drop the .m file all the variables i can see in workspace but i run the same .m file via GUI i am not able to see anything in workspace. please help me on the same matter thanks mahadev

回答 (4 件)

Walter Roberson
Walter Roberson 2012 年 5 月 25 日
Use assignin() if it is important to save a variable to the "base" workspace.
Scripts write into the workspace of their calling function. Scripts run from the command line write into the "base" workspace. You are running a script from the GUI, so it is running in the workspace of some GUI function routine, and then those variables get removed when that GUI function routine returns.
Read about workspaces and function workspaces and assignin(). And about how to construct your script as a function that can be called from another function instead of counting on the "base" workspace.
  2 件のコメント
Brandon
Brandon 2013 年 11 月 4 日
It was interesting to learn about "assignin()" and the difference between base and function workspaces. After reading some, though, it seems that the "best practice" is to use input and output to assign variables to the base workspace. That is:
Walter is correct, but Mathworks suggests using assignin() "sparingly."

サインインしてコメントする。


Sheng Zhu
Sheng Zhu 2017 年 4 月 20 日
try evalin in the GUI programming.
>> doc evalin
Execute MATLAB expression in specified workspace
e.g. evalin('base', 'mfile'); runs mfile in the base workspace

m s
m s 2012 年 5 月 25 日
please someone reply .. i am struggling a lot .. not able to find the way out

Diego Alonso
Diego Alonso 2013 年 2 月 15 日
In a Matlab GUI, the transfer of data among different functions is mainly done with the handles. Hence, your need to include your variables within the handles struct.
handles.data.yourData = load('yourFile.mat');
guidata(handles.yourGUI, handles);

カテゴリ

Help Center および File ExchangeGet Started with MATLAB についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by