How to fprintf a 1 column matrix of random length

3 views (last 30 days)
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!

Accepted Answer

Star Strider
Star Strider on 7 Mar 2022
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 Comments
Star Strider
Star Strider on 7 Mar 2022
My pleasure!
If my Answer helped you solve your problem, please Accept it!
.

Sign in to comment.

More Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!