Need to print the output to newline while creating a table

5 ビュー (過去 30 日間)
Praveen Kumar Kannappan Jayaraman
Praveen Kumar Kannappan Jayaraman 2022 年 11 月 26 日
コメント済み: Star Strider 2022 年 11 月 27 日
I am trying to create a table while running a loop. However, the output is printing the variable name each time it iterates over the loop. I know we have \n command while using fprintf but for table it doesn't seem to work. Please help! Thanks in advance.

採用された回答

Star Strider
Star Strider 2022 年 11 月 26 日
In the loop, subscript the different assignments, for example:
Var1(j,:) = type(j);
Var2(j,:) = dx(j);
and so for the rest. (The subscript ‘(j,:)’ forces a column vector, important when creating a table.)
Then, after the loop, create the table.
Example —
Varname = {'type','dx','dy'};
for j = 1:5
Var1(j,:) = randi(j);
Var2(j,:) = randi(10^j);
Var3(j,:) = randi(100^j);
end
T1 = table(Var1,Var2,Var3, 'VariableNames',Varname)
T1 = 5×3 table
type dx dy ____ _____ __________ 1 7 2 2 23 9088 3 970 3.1255e+05 4 6988 5.2791e+07 2 62912 3.8159e+09
.
  2 件のコメント
Praveen Kumar Kannappan Jayaraman
Praveen Kumar Kannappan Jayaraman 2022 年 11 月 27 日
Thank you so much.
Star Strider
Star Strider 2022 年 11 月 27 日
As always, my pleasure!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

タグ

製品


リリース

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by