필터 지우기
필터 지우기

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