Azzera filtri
Azzera filtri

How can I output a value in an array, exactly as it is.

5 visualizzazioni (ultimi 30 giorni)
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.

Risposte (2)

Jan il 16 Mar 2023
Modificato: Jan il 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"]
a = 1×2 string array
"01" "00e2"
b = {'01', '00e2'}
b = 1×2 cell array
{'01'} {'00e2'}
fprintf('%s ', a)
01 00e2
fprintf('%s ', b{:})
01 00e2
Note than [01,00e2] is not just displayed as [1,0], but it is [1,0].

Praveen Reddy
Praveen Reddy il 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.
Please refer to the following MATLAB documentation:


Scopri di più su Data Type Conversion in Help Center e File Exchange


Community Treasure Hunt

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

Start Hunting!

Translated by