Why does my Command Window show different variables then my workspace?
8 ビュー (過去 30 日間)
古いコメントを表示
I am creating a gui and I have some nested functions which are called from the GUI callback functions. One is called validateFolder(handles, source). When I debug inside this function, I expect to see the function variables only. When I put the breakpoint at the top of the function, I should see handles and source in the workspace, and nothing more. When I use whos in the command winodw, that is what I see. But my workspace, which indicates that its displaying the workspace for the validateFolder() function, shows a different set of variables. Note that this problem is not isolated to this script (it happens in other programs I write too). See screen shot of function, command window, and workspace below:
Here is the full code from the function:
function handles = validateFolder(handles, source)
dataFolder = handles.folders.dataFolder;
isMissing = missingFiles(dataFolder, source);
if ~isMissing
set(handles.gui.btn_load, 'enable', 'ON');
set(handles.gui.rb_fromraw, 'enable', 'ON', 'value', 1);
message = ['Ready to load data from: ' source.studentInfo];
displayMessage(message, handles.gui.message_statusA, [.04 .4 .26]);
else
files = struct2cell(source);
set(handles.gui.btn_load, 'enable', 'OFF');
message = ['Curent Data Folder has no valid source file - add ' files{isMissing}];
displayMessage(message, handles.gui.message_statusA, 'red');
end
3 件のコメント
回答 (1 件)
Jan
2019 年 5 月 15 日
So do I understand correctly: validateFolder() is a nested function. If you stop the debugger inside it, whos displays the variables defined locally inside the nested function, while the Workspace Browser shows the variables defined in the caller also.
If this is the situation, what is the problem you want to solve?
According to the documentation, whos should display two sections if called from inside a nested function, see https://www.mathworks.com/help/matlab/ref/whos.html . But the who does reply the local variables only: https://www.mathworks.com/help/matlab/ref/who.html (search for "nested" in both cases).
2 件のコメント
Jan
2019 年 5 月 16 日
@Dawn MaxIsaac: It would have been useful to see the code, from where the function is called. This is what I meant with "the relevant part of the code". The description as text does not get really clear to me. The nested function can be called from the surrounding function only. If the caler does not provide th input arguments handles, source, the values are taken from the variables defined in the caller - this is the purpose of nested functions.
I consider the calling tree of functions created by GUIDE as too complex to be clean. I prefer to create GUIs programmatically, such that callbacks are called directly without and indirections. Then data are shared over the UserData and/or ApplicationData.
参考
カテゴリ
Help Center および File Exchange で Workspace Variables and MAT-Files についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!