How to fprintf a 1 column matrix of random length
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Sam Lansink
le 7 Mar 2022
Commenté : Star Strider
le 7 Mar 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 commentaires
Réponse acceptée
Star Strider
le 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].')
.
2 commentaires
Star Strider
le 7 Mar 2022
My pleasure!
If my Answer helped you solve your problem, please Accept it!
.
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!