How to fprintf a 1 column matrix of random length
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Sam Lansink
el 7 de Mzo. de 2022
Comentada: Star Strider
el 7 de Mzo. de 2022
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!
0 comentarios
Respuesta aceptada
Star Strider
el 7 de Mzo. de 2022
Try this —
v = [10.5000
18.0000
16.5000
21.0000];
L = 1:numel(v);
fprintf('Row %3d is %g\n',[L(:) v].')
.
2 comentarios
Star Strider
el 7 de Mzo. de 2022
My pleasure!
If my Answer helped you solve your problem, please Accept it!
.
Más respuestas (0)
Ver también
Categorías
Más información sobre Loops and Conditional Statements en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!