How to fprintf a 1 column matrix of random length

3 ビュー (過去 30 日間)
Sam Lansink
Sam Lansink 2022 年 3 月 7 日
コメント済み: Star Strider 2022 年 3 月 7 日
I have my program to the point where I will have a 1 column matrix with 1-10 rows and all values are either 1/2 or whole integers. I am wondering how I can set up an fprintf, a loop or some situation to display in such order
How my program currently works
if matrix is
10.5000
18.0000
16.5000
21.0000
desired output would be
Row 1 is 10.5
Row 2 is is 18
Row 3 is 16.5
Row 4 is 21
Currently I have my matrix saved as o and if I do
fprintf('Row sum is%.0d \n',o)
Then it outputs the integers that arent whole in scientific notation as well
Row sum is 1.05e+01
How to display in normal notation
Thank You!

採用された回答

Star Strider
Star Strider 2022 年 3 月 7 日
Try this —
v = [10.5000
18.0000
16.5000
21.0000];
L = 1:numel(v);
fprintf('Row %3d is %g\n',[L(:) v].')
Row 1 is 10.5 Row 2 is 18 Row 3 is 16.5 Row 4 is 21
.
  2 件のコメント
Sam Lansink
Sam Lansink 2022 年 3 月 7 日
Thank you, works great now!
Star Strider
Star Strider 2022 年 3 月 7 日
My pleasure!
If my Answer helped you solve your problem, please Accept it!
.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by