Use the value in month to extract that month's data from your weatherData matrix and store it in a new vector m. Because January has 31 days, you should only see values in m that are positive or zero (no values of -99999 ).
@reemii
Okay so this is only a small part of an assignment.
so i imported the xls file into matlab and used a command to convert it into an MAT file. So I have it saved in my current folder as MAT. The part I posted I don't understand what it is asking.
M = weatherdata
From what I read, I think you must write \(\verb+month = 1+\) somewhere and then just extract the data: \(\verb|januaryData = weatherData[month];|\) (does this work?) The person making the statement knows the values for January are all >= 0. It's kind of a check for you that you did it right..
hold on
>> JanData = weatherdata(month) JanData = 0
what is the result of `size(weatherdata)` ?
it's a 12x31 that is a typo btw
i mean 31x12 is a typo
the xls file came in a 12x31 matrix
If weatherdata(month) gives `0`, that means weatherdata is a vector (1 x 365) , isn't it ?
maybe it's your method to load the matrix that isn't right
your first comment I am not sure what you mean 1x365. the zero (0) indicates that somethng is at fault?
the excel file is a 12x31 matrix. The file the instructor provided us
What I think is: if weatherdata is indeed 31x12 (or 12x31), then weatherdata(1) is going to be a vector of length 12 (or 31). But weatherdata returned `0`, a number. I think that 0 is the first value of what should be the "data vector" for January.
Okay I see what you are saying. Hmmmm
So I asked you to type `size(weatherdata` and see if everything is alright..
>> size(weatherdata) ans = 12 31
maybe you must write `weatherdata(month,:)` . try this..
>> weatherdata(month,:) ans = Columns 1 through 12 0 0 272 0 0 0 0 9 26 1 0 0 Columns 13 through 24 0 50 85 0 0 90 9 0 0 1 15 224 Columns 25 through 31 0 0 0 0 0 33 33
Is it possible? (I don't know enough to say)
hmmm
try weatherdata(12:31) and weatherdata(31:12).. which one is "error" ? I forgot if matlab stores data in matrices by columns or rows .
weatherdata(31:12) ans = Empty matrix: 1-by-0
that is the wrong one.
>> weatherdata(12:31) ans = Columns 1 through 12 0 0 103 0 1 0 0 0 45 0 0 163 Columns 13 through 20 0 272 0 17 0 0 30 0
sorry. I meant, weatherdata(12,31) VS weatherdata(31,12)
>> weatherdata(12,31) ans = 0 >> weatherdata(31,12) Index exceeds matrix dimensions.
@phi
ok, first index is for months, second one is for days. Then weatherdata(month, 1:31) (is probably the same as weatherdata(month,:) , but check it) is the correct code.
this is a bit long.
can you summarize what you are trying to do ?
@reemii i thought you left that is why I called phi over.
@reemii those are both the same
ok , I see the pdf write up. But it's a bit hard to demonstrate without the data.
laptop crash :-)
can you post the data here?
well I have the data important into lab and converted into mat file
I think that the problem is solved. @phi @raffle_snaffle
let me post the data here. give me a sec
@reemii how so?
I made you check that the size of the matrix is 12x31: `weatherdata(1,:)` gives you a vector of 31 values.
are we in an agreement that the 12x31 matrix is legit and it's not suppose to be 31x12?
@phi that 31x12 is a typo
1) You know how to access to the data. So it's fine. 2) Maybe it's not a typo, I think that MATLAB stores matrices' rows "vertically" .. something like that. Anyway, 1) is more important than 2).
OK, I loaded it into Octave (freeware version of matlab) and have a 12 x 31 matrix
I assume the 12 is the month. if you want all the data for the nth month you would do A= weather_data(n,:) for example, for Jan (month 1) you would get >> Jan= weather_data(1,:) Jan = Columns 1 through 14: 0 0 272 0 0 0 0 9 26 1 0 0 0 50 Columns 15 through 28: 85 0 0 90 9 0 0 1 15 224 0 0 0 0 Columns 29 through 31: 0 33 33
what did you define n as ? is that your month?
>> A = weatherdata(n,:) Undefined function or variable 'n'.
Here is part of what they want >> month= 1 month = 1 >> m= weather_data(month,:) m = Columns 1 through 14: 0 0 272 0 0 0 0 9 26 1 0 0 0 50 Columns 15 through 28: 85 0 0 90 9 0 0 1 15 224 0 0 0 0 Columns 29 through 31: 0 33 33 >> m_avg= mean(m) m_avg = 27.355 >> m_max= max(m) m_max = 272 >>
Okay that is nice to know I was in the right direction after m = weathedata(month,:)
Okay I think that is all I wanted to know for now. Thanks for clearing that up for me @phi.
wait. how would we % days in which max. rain fell in inches
For the days on which the max occurs, do d_max= find(m==m_max)
d_zero= find(m==0) d_zero = Columns 1 through 17: 1 2 4 5 6 7 11 12 13 16 17 20 21 25 26 27 28 Column 18: 29
>> nd_zero= length(d_zero) nd_zero = 18
>> d_max = find(m == m_max) Undefined function or variable 'm_max'.
oops...
you have to find m_max before you can use it. It is (almost) the first thing I did way up above.
clc ; clear % clear window and workspace month = 1; % defined variable m = weatherdata(month,:); % extract months data m_avg = mean(m); % average rain fall per day in inches m_max = max(m); % max. rain fall per day in inches d_max = find(m == m_max); % days in which max. rain fell in inches
yes, that should work. >> d_nonzero= find(m>0) d_nonzero = 3 8 9 10 14 15 18 19 22 23 24 30 31
Error in lab02 (line 7) m = weatherdata(month,:); % extract months data
what is the name of your data? I thought it was weather_data
>> nd_nonzero= length(d_nonzero) nd_nonzero = 13
>> m_avg_nonzero= mean(m(d_nonzero)) m_avg_nonzero = 65.231
it's but for the longest time i was useing weatherdata and it was ouputting the vector
if you type whos it shows what variables exist
now my data doesn't want to load,, let e try that @phi
i cleared everything from my workspace and tried to load(weather_data)
okay I need to restart matlab... It's not running any of the code in my command window
I would use quotes around the filename load("weather_data")
lol @phi thanks.
clc ; clear % clear window and workspace month = 1; % defined variable m = weatherdata(month,:); % extract months data m_avg = mean(m); % average rain fall per day in inches m_max = max(m); % max. rain fall per day in inches d_max = find(m == m_max); % days in which max. rain fell in inches
so when I load(weather_data) into my workspace it appears in the workspace as weatherdata without the _
Reference to a cleared variable weatherdata. Error in lab02 (line 8) m = weatherdata(month,:); % extract months data
yes, if you save variables to a file, you can name the file anything you want. you could for example, save("my_stuff") and it saves the entire workspace
what do you get after loading the file? can you post the result of whos ?
>> whos Name Size Bytes Class Attributes month 1x1 8 double >>
no weather data? try to load it and do whos again
>> whos weatherdata Name Size Bytes Class Attributes weatherdata 12x31 2976 double
do you do a clear *after* the load? that is a bad idea you want to do the clear then load the data
>> clear >> load('weather_data') >> whos weatherdata Name Size Bytes Class Attributes weatherdata 12x31 2976 double
clc ; clear % clear window and workspace load('weather_data') month = 1; % defined variable m = weatherdata(month,:); % extract months data m_avg = mean(m); % average rain fall per day in inches m_max = max(m); % max. rain fall per day in inches d_max = find(m == m_max); % days in which max. rain fell in inches
okay got it
okay it runs well so far. I am going to finish putting in the rest of the commands.
clc ; clear % clears command and workspace window load('weather_data'); % loads data month = 1; % defined variable m = weatherdata(month,:); % extract months data m_avg = mean(m) % average rain fall per day in inches m_max = max(m) % max. rain fall per day in inches d_max = find(m == m_max) % days in which max. rain fell in inches d_zero = find(m == 0) % days in which zero inches fell per day nd_zero = length(d_zero) % number of days in which zero inches fell per day d_nonzero = find(m>0) % days in which at least some rain fell
I had to fix a few things
hold up for a sec. I need to read up on the command find and command length
>> A = [1 4 12 0 9 2]; >> find(A) ans = 1 2 3 5 6
in our case we were telling find what to do? find(m == m_max); find the month with the max rainfall?
find(A) would return the indices of where A is non-zero find(m== m_max) returns the indices where the value == the max value for example, try it on tmp= [1 5 5 1] find(tmp==5) will return 2 and 3 because tmp(2) and tmp(3)= 5
|dw:1460510838427:dw|
Join our real-time social learning platform and learn together with your friends!