convert a variable string to data
6 ビュー (過去 30 日間)
古いコメントを表示
it's needed to convert a variable string to data. for example NAME is string and in a loop could be i=1>>NAME='abd', i=2>>>NAME='fdr',.... now how to convert this string to data. its needed this variable string being matrix.
for example:
q=[];
for i:5
q=[q;i+1];
NAME=q; % i know this is wrong because NAME is string but here i need converting string to data
end
2 件のコメント
Fangjun Jiang
2011 年 9 月 11 日
What do you mean "string to data"? If NAME='abd', what should the data be?
回答 (2 件)
Fangjun Jiang
2011 年 9 月 11 日
If you really need to do this, eval(),evalin() or assignin() is the function to use. This is the same question as your previous one. There is no other way. But I highly recommend you read the link I provided. You could use structure which is very close to what you want.
Name={'abd','fdr'};
data=struct;
for k=1:length(Name)
data=setfield(data,Name{k},rand);
end
data =
abd: 0.65375734866856
fdr: 0.49417393663927
2 件のコメント
Fangjun Jiang
2011 年 9 月 11 日
Well, for numeric data/digits, there is.
a=num2str(3.14159)
b=str2num(a)
参考
カテゴリ
Help Center および File Exchange で Data Type Conversion についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!