MATLAB Answers

How can i convert this string into an input for a function?

5 views (last 30 days)
Robu Robert
Robu Robert on 24 Apr 2021
Commented: Stephen Cobeldick on 25 Apr 2021
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 Comments

Sign in to comment.

Answers (1)

Rik
Rik on 24 Apr 2021
ch=['MRWI'
'IDMZ'
'CGBI'
'JKNO'];
v=ch.';v=v(:).';
disp(v)
  2 Comments
Rik
Rik on 25 Apr 2021
Then you need cell2mat, after which you can use {:} to create a comma separated list.

Sign in to comment.

Tags

Community Treasure Hunt

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

Start Hunting!