How to create variables using strings in an array?
Mostra commenti meno recenti
str1={'x','trs','height','width'}
str2='db_xtr'
For example, I wanted to do:
for ivar=1:size(str1,2)
C_%str1%_%str2%=ivar^2+2
end
to get following variables:
C_x_db_xtr = 1^2+2
C_trs_db_xtr = 2^2+2
C_height_db_xtr = 3^2+2
C_width_db_xtr = 4^2+2
seems function "genvarname" would do something similar but do not know how to do it for my particular case.
Thanks...
Risposta accettata
Più risposte (1)
Andrei Bobrov
il 15 Set 2013
str1={'x','trs','height','width'}
str2='db_xtr'
input1 = [strcat(str1,'_',str2);num2cell((1:numel(str1)).^2+2)]
C = struct(input1{:})
2 Commenti
J. Hu
il 15 Set 2013
Walter Roberson
il 15 Set 2013
Don't do that.
C{ivar1}{ivar2} = ... some matrix expression ...
Categorie
Scopri di più su Cell Arrays in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!