Setting a string as a variable name

5 vues (au cours des 30 derniers jours)
Ariel Edesess
Ariel Edesess le 26 Sep 2016
Commenté : Stephen23 le 26 Sep 2016
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

Réponses (0)

Catégories

En savoir plus sur Variables dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by