Why does my Command Window show different variables then my workspace?

8 ビュー (過去 30 日間)
Dawn MacIsaac
Dawn MacIsaac 2019 年 5 月 15 日
コメント済み: Jan 2019 年 5 月 16 日
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 件のコメント
Dawn MacIsaac
Dawn MacIsaac 2019 年 5 月 15 日
I am not sure what is meant by not being able to see relavent parts of the code...I think the only relavent part of the code is what is inside the function, which is visible. What the code actually does inside the function after the breakpoint is completely irrelavent, but I will cut and paste it for you if you think it will help.
Dawn MacIsaac
Dawn MacIsaac 2019 年 5 月 15 日
Also - the variables that are being displayed in the workspace are familiar, and I think are variables visible in one of the callback functions that calls validateFolder().

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

回答 (1 件)

Jan
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 件のコメント
Dawn MacIsaac
Dawn MacIsaac 2019 年 5 月 15 日
Thanks for the information. I am OK with what whos is displaying - only the local variables (even though, I guess based on your answer, that it should display both local and caller variables). The problem is that the Workspace panel is NOT displaying the local variables. If you look at the diagram, the title of the workspace is Workspace - validateFolder, but it doesn't display any of the variables local to that function. This isn't typical, and can't be the expected behavior for the Wokspace display panel?
I think it has to do with the fact that the function is being called before the GUI opens (ie it is called from the opening function of the GUI). When I call it again from a GUI object callback function after the GUI opens (eg. a button press), both whos and the Workspace panel display only the local variables. This, I think, is the expected behavior.
Jan
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 ExchangeWorkspace Variables and MAT-Files についてさらに検索

製品


リリース

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by