Going from a Matrix of months to a date.

17 ビュー (過去 30 日間)
Nicholas Carlson
Nicholas Carlson 2015 年 10 月 18 日
回答済み: Walter Roberson 2015 年 10 月 18 日
Days_into_Month = cell(n,1);
Month = char(Month(1:n,1));
for d = (1:n)'
switch Month(d,1)
case {'Jan'}
Days_into_Month(d,1) = {Total_Days(d,1) +6};
case {'Feb'}
Days_into_Month(d,1) = {Total_Days(d,1) - 24};
case {'Mar'}
Days_into_Month(d,1) = {Total_Days(d,1) - 53};
case {'Apr'}
Days_into_Month(d,1) = {Total_Days(d,1) - 84};
case {'May'}
Days_into_Month(d,1) = {Total_Days(d,1) - 114};
case {'Jun'}
Days_into_Month(d,1) = {Total_Days(d,1) - 145};
case {'Jul'}
Days_into_Month(d,1) = {Total_Days(d,1) - 175};
case {'Aug'}
Days_into_Month(d,1) = {Total_Days(d,1) - 206};
case {'Sep'}
Days_into_Month(d,1) = {Total_Days(d,1) - 237};
case {'Oct'}
Days_into_Month(d,1) = {Total_Days(d,1) - 267};
case {'Nov'}
Days_into_Month(d,1) = {Total_Days(d,1) - 298};
case {'Dec'}
Days_into_Month(d,1) = {Total_Days(d,1) - 328};
case {'Ja_'}
Days_into_Month(d,1) = {Total_Days(d,1) - 359};
Actual_Year = Actual_Year + 1;
end
end
I am looking for my matrix to come back with different numbers varying to each month.
Month =
'Mar'
'Dec'
'Oct'
'Oct'
'May'
'Jul'
'Dec'
This is the current month data set that I have and i need Days_into_Month to be a result of Total_Days(d,1) subtract the corresponding number.

回答 (1 件)

Walter Roberson
Walter Roberson 2015 年 10 月 18 日
dayoff = [6, -24, -53, -84, .... -359];
[tf, monidx] = ismember(Month, {'Jan', 'Feb', 'Mar', .... 'Dec', 'Ja_'});
Days_into_Month = Today_days + dayoff(monidx);

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by