Info

This question is closed. Reopen it to edit or answer.

I have an if else statement that runs through a matrix and the answer needs to be in matrix form

1 view (last 30 days)
n = input('How many sets of data is in the file? \n');
Month = (1:n)';
for d = (1:n)'
Total_Days = ((Weeks_into_Year * 7) + Days_into_Week);
if (0 <= Total_Days(d,1))&(Total_Days(d,1) <= 24) 
    Month(d,1) = 'Jan';
elseif (25 <= Total_Days(d,1))&(Total_Days(d,1) <= 53)
    Month(d,1) = 'Feb';
elseif (54 <= Total_Days(d,1))&(Total_Days(d,1) <= 84)
    Month(d,1) = 'Mar';
elseif (85 <= Total_Days(d,1))&(Total_Days(d,1) <= 114)   
    Month(d,1) = 'Apr';
elseif (115 <= Total_Days(d,1))&(Total_Days(d,1) <= 145)   
    Month(d,1) = 'May';
elseif (146 <= Total_Days(d,1))&(Total_Days(d,1) <= 175)   
    Month(d,1) = 'Jun';
elseif (176 <= Total_Days(d,1))&(Total_Days(d,1) <= 206)
    Month(d,1) = 'Jul';
elseif (207 <= Total_Days(d,1))&(Total_Days(d,1) <= 237)   
    Month(d,1) = 'Aug';
elseif (238 <= Total_Days(d,1))&(Total_Days(d,1) <= 267)
    Month(d,1) = 'Sep';
elseif (268 <= Total_Days(d,1))&(Total_Days(d,1) <= 298)   
    Month(d,1) = 'Oct';
elseif (299 <= Total_Days(d,1))&(Total_Days(d,1) <= 328)
    Month(d,1) = 'Nov';
elseif (329 <= Total_Days(d,1))&(Total_Days(d,1) <= 359)
    Month(d,1) = 'Dec';
elseif (360 <= Total_Days(d,1))&(Total_Days(d,1) <= 364)
    Month(d,1) = 'Jan';
end
end

This is my code and i need to have a matrix answer of multiple months in a vertical column.

  1 Comment
Image Analyst
Image Analyst on 16 Oct 2015
You forgot to show us what the answer is supposed to look like. Show us that and we might be able to tell you how to create it.
Is this homework?

Answers (1)

Walter Roberson
Walter Roberson on 16 Oct 2015
Month = cell(1,n);
and in the loop,
Month{1,d} = 'Jan' or 'Feb' or 'Mar' etc.
Hint: consider using the second output from histc()
  2 Comments
Nicholas Carlson
Nicholas Carlson on 16 Oct 2015
Edited: Walter Roberson on 16 Oct 2015
>> Setting_Date_1
How many sets of data is in the file?
7
>> Month
Month =
[]
[]
[]
[]
[]
[]
[]
This is what I get when I make the changes you recommend and I can't seem to put a value in that returns a month other than when I put in 1.

Community Treasure Hunt

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

Start Hunting!