I need to turn a 7x1 matrix full of numbers into a 7x1 matrix full of names but I don't know what I'm doing.
10 ビュー (過去 30 日間)
古いコメントを表示
I need to convert a matrix filled with the number day of the year into a matrix that tells me what month each of those days falls in. I tried just doing
if days<31
month='January'
that obviously didn't work. next I tried using a for loop
for n=1:7
days(n)<31
month(n,1)='January'
but that also didn't work. Anyone know what to do?
0 件のコメント
回答 (2 件)
Star Strider
2015 年 10 月 17 日
This does not want to be vectorised, so you would have to loop through it for each day number, but it will probably do what you want:
daysvct = cumsum(eomday(2015, 1:12));
daynr = 123;
mnthnr = find(daysvct < daynr, 1, 'last');
mnthstr = datestr([2015 mnthnr 01 00 00 00], 'mmmm');
out = sprintf('Day #%d is in %s', daynr, mnthstr)
out =
Day #123 is in April
0 件のコメント
Walter Roberson
2015 年 10 月 17 日
Hint:
months = {'January', 'February', 'March'};
months([3 1 2 2 3 1])
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Creating and Concatenating Matrices についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!