How can I output a value in an array, exactly as it is.
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Currently I am trying to output this array: [01,00e2], but it gets outputted as:
1 0
When I would like it to be
01 00e2.
How can I make the output exactly like the array I am inputting.
0 commentaires
Réponses (2)
Jan
le 16 Mar 2023
Modifié(e) : Jan
le 16 Mar 2023
01 is no valid notation of a number. Numerically leading zeros are not existing. Zeros multiplied by a power of ten are still zeros, so they are displayed as 0.
You want to display a specific sequence of characters. This is done by CHAR vectors and strings, but not by numerical values.
a = ["01", "00e2"]
b = {'01', '00e2'}
fprintf('%s ', a)
fprintf('%s ', b{:})
Note than [01,00e2] is not just displayed as [1,0], but it is [1,0].
0 commentaires
Praveen Reddy
le 16 Mar 2023
Hi Ashwin,
I understand that you want to store 01, 00e2 as is and display them. However internally there is no object like 01 if the number 1 is meant. Similarly, 00e2 if 0 is meant. They get stored as 1 , 0 respectively. You can add leading zeroes, only if you represent 1 as a string. Similarly, 00e2.
If you want to see the same output try to store them as x=[“01”,”00e2”].
You can also use 0 padding if you want to display 1 as 01.
x=[1,2];
fprintf("%02d",x(1,1));
fprintf("%02d",x(1,2));
Please refer to the following MATLAB documentation:
0 commentaires
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!