Moving large matrix from function workspace to base workspace?

2 ビュー (過去 30 日間)
S. Boopalam
S. Boopalam 2020 年 3 月 17 日
コメント済み: Walter Roberson 2020 年 3 月 17 日
I am debugging a program and want to get some matrix data out of the program and into the base workspace, so I can probe it and try a fews things on it. How can I do this? I having been uising the following command, but the mat2str function takes a while (and also adds on extra precision for some reason):
evalin('base', ['datamat = ' mat2str(data) ';'])

採用された回答

Stephen23
Stephen23 2020 年 3 月 17 日
編集済み: Stephen23 2020 年 3 月 17 日
The correct function to use is assignin, not evalin:
assignin('base','data',data)
Probably even better would be to just use the debugging tools: use a breakpoint to stop the code on a suitable line, and then look at whatever variables you want. This means you do not need to add code or change the function, and gives you access to all variables in that workspace:
  2 件のコメント
S. Boopalam
S. Boopalam 2020 年 3 月 17 日
Thanks. Is it possible to do the opposite: import a base workspace matrix into the function workspace?
Walter Roberson
Walter Roberson 2020 年 3 月 17 日
workspace_variable_name_goes_here = evalin('base', 'base_workspace_variable_name_goes_here');
Note that you will not be able to do this if your function declaration has a matching end declaration, or if you are debugging an anonymous function. In those cases, the workspace is declared "static", meaning that no new variables can be added to it by using assignin() or at the debugger command line.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeNumeric Types についてさらに検索

製品


リリース

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by