Info

この質問は閉じられています。 編集または回答するには再度開いてください。

How do I reserve a size for my data so that zero's are not dropped or forgotten?

1 回表示 (過去 30 日間)
Greg
Greg 2013 年 4 月 11 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
I am writing for determining what day of the week it is. I am using 'num2str' to create a string for my user 'year' entry and 'str2double' to recall the last two and first two digits separately. This method falls apart when I attempt to determine the day of the week when the year is very small. For example, 01/01/0003. Is there a way to store the zeros to make this work or do I have to write a lot of 'if' statements? If you know of another way besides the build in method, it would be appreciated.
  5 件のコメント
PT
PT 2013 年 4 月 11 日
If you really want to reserve zeros in front of a number so it is always 4 characters long when converting to string, do
Yr = num2str(Y, '%04i');
Greg
Greg 2013 年 4 月 11 日
Thank you very much, that did the trick.

回答 (1 件)

PT
PT 2013 年 4 月 11 日
Use
datevec(datenum('01/02/0003'))
The output will be in the form of
[ Year Month Day Hour Minute Second ]

この質問は閉じられています。

Community Treasure Hunt

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

Start Hunting!

Translated by