Accessing and editing workspace values in matlab code
古いコメントを表示
I need to search a variable in workspace and edit its value at some specific index. How do i access, edit that variable and save new value back to workspace. Thanks,
採用された回答
その他の回答 (2 件)
Friedrich
2011 年 7 月 8 日
I think what you are looking for is the evalin command. So something like
evalin('base','a=3')
Or if you really have to search you can do:
var = evalin('base','whos;')
6 件のコメント
Sadanand
2011 年 7 月 8 日
Friedrich
2011 年 7 月 8 日
You can do it this way:
%base workspace
base_array = 1:10;
%do this in function
array = evalin('base','base_array;')
array(3) = 37;
assignin('base','base_array',array)
But this will copy the full array everytime.
Friedrich
2011 年 7 月 8 日
Or when single value is needed:
array_at_index = evalin('base','base_array(3);')
array_at_index = array_at_index * 2;
assignin('base','tmp',array_at_index)
evalin('base','base_array(3) = tmp;clear tmp;')
Sadanand
2011 年 7 月 8 日
Friedrich
2011 年 7 月 8 日
Sure evalin('base',x) throws an error since x is not present it the ML workspace. you have to ways here how to proceed and both are stated above:
1.) assignin('base','ABC',x) %will overwrite variable ABC with the values of x
2.)assignin('base','x',x) %copy the variable in the ML Workspace
evalin('base','ABC(some_index) = x; clear x')
Sadanand
2011 年 7 月 8 日
yasser
2013 年 11 月 11 日
0 投票
am looking for value in some workspaces, can i get name of workspace and index of [row,col]? how to do that?
カテゴリ
ヘルプ センター および File Exchange で Data Import and Export についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!