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 Center および File ExchangeVariables についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by