Accessing and editing workspace values in matlab code
조회 수: 5 (최근 30일)
이전 댓글 표시
채택된 답변
Friedrich
2011년 7월 8일
You code looks correct so far (little typo in the assignin command, it must be array instead of arraya). But I think this should be faster since you have to copy one value only:
function test(mystruct)
for i=1:1
assignin('base','tmp',mystruct(i).value)
cmd_string = [mystruct(i).name,'(',num2str(mystruct(i).rowIndex),',',num2str(mystruct(i).colIndex),')=tmp;clear tmp'];
evalin('base',cmd_string)
end
end
I tested it with:
a = [1 2 3 4]
mystruct.name = 'a'
mystruct.rowIndex = 1;
mystruct.colIndex = 1;
mystruct.value = 14;
test(mystruct)
추가 답변 (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
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')
yasser
2013년 11월 11일
am looking for value in some workspaces, can i get name of workspace and index of [row,col]? how to do that?
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!