필터 지우기
필터 지우기

Is it possible to dereference a string variable inside evalin()?

조회 수: 5 (최근 30일)
For example inside a function I have:
VAR_A = 'somevar_in_base';
% I want to test if 'somevar_in_base' by name exist in 'base' workspace
evalin('base', 'exist(''VAR_A'', ''var'')')
local = evalin('base', 'VAR_A');
Above lines do not extend "VAR_A". Is it possible to get what I want with minor changes or should I avoid coding this way?
Thanks,

채택된 답변

Walter Roberson
Walter Roberson 2013년 3월 12일
evalin('base', sprintf('exist(''%s'', ''var''), VAR_A) )
evalin('base', VAR_A)
You could also consider
try
local = evalin('base', VAR_A);
catch
%do whatever as it does not exist
end

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

태그

아직 태그를 입력하지 않았습니다.

제품

Community Treasure Hunt

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

Start Hunting!

Translated by