Setting a string as a variable name

조회 수: 2 (최근 30일)
Ariel Edesess
Ariel Edesess 2016년 9월 26일
댓글: Stephen23 2016년 9월 26일
Hi there,
This is probably a very silly question but I'm using the follow snippet of code to extract some info from a data file. There are 5 values I would like to extract (i.e. numel(specVar) = 5), and the first one is a word while the last 4 are numbers. In my " if i == 1 " loop, I would like to assign the value from temp to specVal(1), rather than convert the string to a double , as I'm doing with specVal(2-5). I'm pretty sure this is just one simple command but "string(temp{2})" does not do it (obviously). What would be the right way to do this?
for i = 1:numel(specVar)
% FIND VALUE OF VARIABLES
expr = specVar(i);
[matchstart,~,~,~,~,~,splitstring] = regexpi(string,expr);
% ASSIGN THE VALUE TO THE VARIABLES
if ~isempty(cell2mat(matchstart))
temp = splitstring{1};
if i == 1
specVal(i) = string(temp{2});
end
specVal(i) = str2double(temp{2});
end
end

답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by