How can I output a value in an array, exactly as it is.
4 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
回答 (2 件)
Jan
2023 年 3 月 16 日
編集済み: Jan
2023 年 3 月 16 日
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 件のコメント
Praveen Reddy
2023 年 3 月 16 日
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 件のコメント
参考
カテゴリ
Help Center および File Exchange で Data Type Conversion についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!