Use of Evalin

5 次查看(过去 30 天)
Karthik KJ
Karthik KJ 2012-4-24
for i=1:str2num(get(handles.nosensorentry_tag,'string'))
set(handles.sensname(i),'string',evalin('base','SensorList.sensorname(i,1)'))
end
I am not able to use loop to get the workspace variable with evalin. Matlab is showing
Error using ==> evalin
Subscript indices must either be real positive integers or logicals.
Is there any way to increment 'i' in evalin statement.

采纳的回答

Walter Roberson
Walter Roberson 2012-4-24
names = evalin('base', 'SensorList.sensorname');
for i = 1:str2num(get(handles.nosensorentry_tag,'string'))
set(handles.sensname(i), 'String', names(i,1));
end

更多回答(2 个)

Daniel Shub
Daniel Shub 2012-4-25
You need to evaulate the i in the current workspace and not the base:
for i=1:str2num(get(handles.nosensorentry_tag,'string'))
set(handles.sensname(i),'string',evalin('base', ...
['SensorList.sensorname(', num2str(i), ',1)']))
end

Jan
Jan 2012-4-25
n = str2num(get(handles.nosensorentry_tag,'string'))
for i = 1:n
set(handles.sensname(i), 'string', SensorList.(sensorname{i}));
end
  1 个评论
Walter Roberson
Walter Roberson 2012-4-25
I believe the idea is that SensorList is defined in the base workspace but not the current workspace.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Migrate GUIDE Apps 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by