Text in while loop creating matrix

조회 수: 3 (최근 30일)
Isai Fernandez
Isai Fernandez 2019년 7월 12일
댓글: Isai Fernandez 2019년 7월 12일
I was trying to create a matrix with text in some cases, but I can't. I tried with advices from other answers, but it didn't work.
The text which I want to include is «start» and «end» for two different cases like this:
NM = 5
FF = zeros(NM*2,2);
start = 'start';
ending = 'end';
while i<=NM
FF(i*2,1) = i
FF(i*2-1,1) = i
FF(i*2,2) = fprintf(start);
FF(i*2-1,2) = fprintf(ending)
i = i+1
  댓글 수: 4
Stephen23 2019년 7월 12일
편집: Stephen23 2019년 7월 12일
"it could be possible to get the the solution working with tables?"
Possibly, but as you have not shown what the expected output should be nor explained what further processing you will do using this data, it is hard to give any advice on this.
Isai Fernandez
Isai Fernandez 2019년 7월 12일
I need to use this block of data to concatenate with other matrix, after that.

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

답변 (1개)

Thorsten 2019년 7월 12일
편집: Thorsten 2019년 7월 12일
You have to use cell arrays if you want to mix text and numbers. And fprintf returns the number of printed bytes, so you directly assign the string to the cell, w/o fprintf:
NM = 5
FF = cell(NM*2,2);
start = 'start';
ending = 'end';
while i<=NM
FF{i*2,1} = i;
FF{i*2-1,1} = i;
FF{i*2,2} = start;
FF{i*2-1,2} = ending;
i = i+1;
  댓글 수: 1
Isai Fernandez
Isai Fernandez 2019년 7월 12일
I need to concatenate after this loop with another matrix. Tables are the solution?

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


Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기




Community Treasure Hunt

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

Start Hunting!

Translated by