フィルターのクリア

Text in while loop creating matrix

2 ビュー (過去 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';
i=1
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
end
  4 件のコメント
Stephen23
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
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';
i=1;
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;
end
  1 件のコメント
Isai Fernandez
Isai Fernandez 2019 年 7 月 12 日
I need to concatenate after this loop with another matrix. Tables are the solution?

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeCharacters and Strings についてさらに検索

製品


リリース

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by