Getting variables in function workspace during debugging
7 ビュー (過去 30 日間)
古いコメントを表示
I'm creating a mlapp data visualization tool and need to grab all variables in the current function workspace when debugging.
When running the app, while debugging a program, the user should be able to press a button when a breakpoint is reached to pull in all variables in the current function workspace to interact with the var data in the app. One main challenge is when this button is pressed, it goes into a callback function, which has its own function workspace within the app. I am using the below code to get each variable and do what I need to do with it:
variables = evalin('base', 'whos')
for ii = 1:numel(variables)
data = evalin('base', variables(ii).name);
% ....
% do something with data
% ....
end
I understand that 'base' is not what we want here. However, evalin only accepts 'base' and 'caller' and 'caller' is not correct either since it's a function of the app. So this is unable to grab the variables within the current function workspace when debugging, only the base workspace. Do you have any idea how to grab the variables for the current function you are in programmatically, while debugging?
7 件のコメント
回答 (1 件)
Steven Lord
2022 年 3 月 7 日
I'm creating a mlapp data visualization tool and need to grab all variables in the current function workspace when debugging.
When you enter debug mode you can switch between function workspaces via icons in the Editor or via the dbup and dbdown functions.
When running the app, while debugging a program, the user should be able to press a button when a breakpoint is reached to pull in all variables in the current function workspace to interact with the var data in the app.
Suppose that the variables in the "current function workspace" have the same name as "data in the app". Are you okay with the "data in the app" being overwritten by some other data (which may or may not be the same size or type or have the same meaning) that happens to have the same name?
Do you have any idea how to grab the variables for the current function you are in programmatically, while debugging?
IMO the answer is "You shouldn't." If you need to check something in the caller's workspace (to check that what your function received is what you expected it to receive) switch workspaces and check the value in situ then switch workspaces back to the workspace where you entered debug mode.
参考
カテゴリ
Help Center および File Exchange で Debugging and Analysis についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!