How do I format an array of values to a specific number of digits?

40 ビュー (過去 30 日間)
Brad
Brad 2016 年 2 月 23 日
コメント済み: Jan 2016 年 2 月 23 日
I've got a 5 X 1 double array that looks like this;
>> Y = [1;2;3;4;5];
>> Y
Y =
1
2
3
4
5
I want to format the contents of Y such that they are;
01
02
03
04
05
Can this be done for an array of values? I've used fprintf for writing formatted data to text file. But it appears this won't work for an array.
Thank you.
  1 件のコメント
Jan
Jan 2016 年 2 月 23 日
Why do you assume, that this does not work? The core of this question is hidden in this sentencs. So please provide the details.

サインインしてコメントする。

採用された回答

Azzi Abdelmalek
Azzi Abdelmalek 2016 年 2 月 23 日
Y = [1;2;3;4;5]
out=sprintf('0%d\n',Y)

その他の回答 (1 件)

Jan
Jan 2016 年 2 月 23 日
Or considering numbers >= 10:
Y = [1;2;3;4;5;10]
out = sprintf('%02d\n',Y)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by