MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn moreOpportunities for recent engineering grads.

Apply Today**New to MATLAB?**

Asked by andrew_cup
on 23 Nov 2012

Hi, I made this program were the user can type in a year between 2009 and 2011 and get snow depth and air temperature data for the chosen year displayed on a graph.

I have one xls file for the temperature for each day from day 1 to day 365. I also have another xls file for snow depth from day 1 to day 212. So some days they didn't bother to measure snow depth because it was summer anyways. Between 30. april to 1. october they didn't measure snow depth. I want to add 153 zeroes with code between 30. april and 1. oct so it adds up to 365 days.

day 121 = 30. april

chosenyear = input('Type in year: ');

snowdepth = xlsread('snow2009_2011.xls');

snowdepth2009 = snowdepth(:,1); snowdepth2010 = snowdepth(:,2); snowdepth2011 = snowdepth(:,3);

airtemp = xlsread('airtemp2009_2011.xls'); airtemp2009 = airtemp(:,1); airtemp2010 = airtemp(:,2); airtemp2011 = airtemp(:,3);

if chosenyear == 2009 figure(1); plot(snowdepth2009, 'b');

title(['Snowdepth/airtemp ' num2str(chosenyear)]); xlabel('Days/months'); ylabel('data');

grid on datetick('x','m');

hold on plot(airtemp2009, 'r'); legend('snow depth in cm','air temp in Celsius');

elseif chosenyear == 2010 figure(2); plot(snowdepth2010, 'b');

title(['Snowdepth/airtemp ' num2str(chosenyear)]); xlabel('Days/months'); ylabel('data');

grid on datetick('x','m');

hold on plot(airtemp2010, 'r'); legend('snow depth in cm','air temp in Celsius');

elseif chosenyear == 2011 figure(3); plot(snowdepth2011, 'b');

title(['Snowdepth/airtemp ' num2str(chosenyear)]); xlabel('Days/months'); ylabel('data');

grid on datetick('x','m');

hold on plot(airtemp2011, 'r'); legend('snow depth in cm','air temp in Celsius');

else disp('NB! Type in 2009, 2010 or 2011'); filename.m end

*No products are associated with this question.*

Answer by Image Analyst
on 23 Nov 2012

Accepted answer

Difficult to test this unless you upload the files. http://www.mathworks.com/matlabcentral/answers/7924-where-can-i-upload-images-and-files-for-use-on-matlab-answers

But in your other post, I told you how to insert rows - did you see that answer?

andrew_cup
on 23 Nov 2012

yes, but when I run the program it stops at 212 days and doesn't display all 12 months. I can upload xls files.

andrew_cup
on 23 Nov 2012

Air temp xls: https://dl.dropbox.com/u/11241083/airtemp2009_2011.xls

Snow depth xls: https://dl.dropbox.com/u/11241083/snow2009_2011.xls

## 0 Comments