How can i convert this string into an input for a function?
古いコメントを表示
Hello, everyone! I have this program:
ch=['MRWI'
'IDMZ'
'CGBI'
'JKNO']
v=[];
[x,y]=size(ch)
for i=1:x
v=[v, 'ch(',num2str(i),',:),']
end
where v will be equal to the string: ''ch(1,:),ch(2,:),ch(3,:),ch(4,:),'. My question is how can i use v as an input for a function? for exemple, to display the values of v as 'MRWI,IDMZ,CGBI,JKNO'
3 件のコメント
David Hill
2021 年 4 月 24 日
Why do you want to do that? You should try not to do that if at all possible.
Robu Robert
2021 年 4 月 24 日
Stephen23
2021 年 4 月 25 日
As David Hill wrote, you should avoid converting data to character representations of the same data.
As Rik wrote, the correct approach is to use a comma-separated list:
Bruno Luong showed you exactly how here:
回答 (1 件)
Rik
2021 年 4 月 24 日
ch=['MRWI'
'IDMZ'
'CGBI'
'JKNO'];
v=ch.';v=v(:).';
disp(v)
2 件のコメント
Robu Robert
2021 年 4 月 24 日
Rik
2021 年 4 月 25 日
Then you need cell2mat, after which you can use {:} to create a comma separated list.
カテゴリ
ヘルプ センター および File Exchange で Characters and Strings についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!