How to fprintf a 1 column matrix of random length

3 visualizzazioni (ultimi 30 giorni)
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!

Risposta accettata

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

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Loops and Conditional Statements in Help Center e File Exchange

Prodotti


Release

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by