필터 지우기
필터 지우기

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

조회 수: 3 (최근 30일)
Robu Robert
Robu Robert 2021년 4월 24일
댓글: Stephen23 2021년 4월 25일
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
Robu Robert
Robu Robert 2021년 4월 24일
Hello, @David Hill . I just try to figure out how can i get to resolve my actual problem, which i described in a previous post ( https://www.mathworks.com/matlabcentral/answers/809040-how-to-get-all-combinations-from-this-matrix ) . So far, i could not come up with anything
Stephen23
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
Rik 2021년 4월 24일
ch=['MRWI'
'IDMZ'
'CGBI'
'JKNO'];
v=ch.';v=v(:).';
disp(v)
  댓글 수: 2
Robu Robert
Robu Robert 2021년 4월 24일
Thank you for your answer. I need the output of the program to be the input for a function named allcomb which looks like this :
allcomb(ch(1,:),ch(2,:),ch(3,:),ch(4,:))
So i can t use the sequence you just proposed
Rik
Rik 2021년 4월 25일
Then you need cell2mat, after which you can use {:} to create a comma separated list.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 String Parsing에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by