Setting a string as a variable name

5 次查看(过去 30 天)
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