Ask your own question, for FREE!
Mathematics 7 Online
OpenStudy (raffle_snaffle):

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 ).

OpenStudy (raffle_snaffle):

@reemii

OpenStudy (raffle_snaffle):

Okay so this is only a small part of an assignment.

OpenStudy (raffle_snaffle):

OpenStudy (raffle_snaffle):

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.

OpenStudy (raffle_snaffle):

M = weatherdata

OpenStudy (reemii):

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..

OpenStudy (raffle_snaffle):

hold on

OpenStudy (raffle_snaffle):

>> JanData = weatherdata(month) JanData = 0

OpenStudy (reemii):

what is the result of `size(weatherdata)` ?

OpenStudy (raffle_snaffle):

it's a 12x31 that is a typo btw

OpenStudy (raffle_snaffle):

i mean 31x12 is a typo

OpenStudy (raffle_snaffle):

the xls file came in a 12x31 matrix

OpenStudy (reemii):

If weatherdata(month) gives `0`, that means weatherdata is a vector (1 x 365) , isn't it ?

OpenStudy (reemii):

maybe it's your method to load the matrix that isn't right

OpenStudy (raffle_snaffle):

your first comment I am not sure what you mean 1x365. the zero (0) indicates that somethng is at fault?

OpenStudy (raffle_snaffle):

the excel file is a 12x31 matrix. The file the instructor provided us

OpenStudy (reemii):

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.

OpenStudy (raffle_snaffle):

Okay I see what you are saying. Hmmmm

OpenStudy (reemii):

So I asked you to type `size(weatherdata` and see if everything is alright..

OpenStudy (raffle_snaffle):

>> size(weatherdata) ans = 12 31

OpenStudy (reemii):

maybe you must write `weatherdata(month,:)` . try this..

OpenStudy (raffle_snaffle):

>> 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

OpenStudy (reemii):

Is it possible? (I don't know enough to say)

OpenStudy (raffle_snaffle):

hmmm

OpenStudy (reemii):

try weatherdata(12:31) and weatherdata(31:12).. which one is "error" ? I forgot if matlab stores data in matrices by columns or rows .

OpenStudy (raffle_snaffle):

weatherdata(31:12) ans = Empty matrix: 1-by-0

OpenStudy (raffle_snaffle):

that is the wrong one.

OpenStudy (raffle_snaffle):

>> 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

OpenStudy (reemii):

sorry. I meant, weatherdata(12,31) VS weatherdata(31,12)

OpenStudy (raffle_snaffle):

>> weatherdata(12,31) ans = 0 >> weatherdata(31,12) Index exceeds matrix dimensions.

OpenStudy (raffle_snaffle):

@phi

OpenStudy (reemii):

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.

OpenStudy (phi):

this is a bit long.

OpenStudy (phi):

can you summarize what you are trying to do ?

OpenStudy (raffle_snaffle):

@reemii i thought you left that is why I called phi over.

OpenStudy (raffle_snaffle):

@reemii those are both the same

OpenStudy (phi):

ok , I see the pdf write up. But it's a bit hard to demonstrate without the data.

OpenStudy (reemii):

laptop crash :-)

OpenStudy (phi):

can you post the data here?

OpenStudy (raffle_snaffle):

well I have the data important into lab and converted into mat file

OpenStudy (reemii):

I think that the problem is solved. @phi @raffle_snaffle

OpenStudy (raffle_snaffle):

let me post the data here. give me a sec

OpenStudy (raffle_snaffle):

@reemii how so?

OpenStudy (raffle_snaffle):

OpenStudy (reemii):

I made you check that the size of the matrix is 12x31: `weatherdata(1,:)` gives you a vector of 31 values.

OpenStudy (raffle_snaffle):

are we in an agreement that the 12x31 matrix is legit and it's not suppose to be 31x12?

OpenStudy (raffle_snaffle):

@phi that 31x12 is a typo

OpenStudy (reemii):

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).

OpenStudy (phi):

OK, I loaded it into Octave (freeware version of matlab) and have a 12 x 31 matrix

OpenStudy (phi):

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

OpenStudy (raffle_snaffle):

what did you define n as ? is that your month?

OpenStudy (raffle_snaffle):

>> A = weatherdata(n,:) Undefined function or variable 'n'.

OpenStudy (phi):

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 >>

OpenStudy (raffle_snaffle):

Okay that is nice to know I was in the right direction after m = weathedata(month,:)

OpenStudy (raffle_snaffle):

Okay I think that is all I wanted to know for now. Thanks for clearing that up for me @phi.

OpenStudy (raffle_snaffle):

wait. how would we % days in which max. rain fell in inches

OpenStudy (phi):

For the days on which the max occurs, do d_max= find(m==m_max)

OpenStudy (phi):

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

OpenStudy (phi):

>> nd_zero= length(d_zero) nd_zero = 18

OpenStudy (raffle_snaffle):

>> d_max = find(m == m_max) Undefined function or variable 'm_max'.

OpenStudy (raffle_snaffle):

oops...

OpenStudy (phi):

you have to find m_max before you can use it. It is (almost) the first thing I did way up above.

OpenStudy (raffle_snaffle):

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

OpenStudy (phi):

yes, that should work. >> d_nonzero= find(m>0) d_nonzero = 3 8 9 10 14 15 18 19 22 23 24 30 31

OpenStudy (raffle_snaffle):

Error in lab02 (line 7) m = weatherdata(month,:); % extract months data

OpenStudy (phi):

what is the name of your data? I thought it was weather_data

OpenStudy (phi):

>> nd_nonzero= length(d_nonzero) nd_nonzero = 13

OpenStudy (phi):

>> m_avg_nonzero= mean(m(d_nonzero)) m_avg_nonzero = 65.231

OpenStudy (raffle_snaffle):

it's but for the longest time i was useing weatherdata and it was ouputting the vector

OpenStudy (phi):

if you type whos it shows what variables exist

OpenStudy (raffle_snaffle):

now my data doesn't want to load,, let e try that @phi

OpenStudy (raffle_snaffle):

i cleared everything from my workspace and tried to load(weather_data)

OpenStudy (raffle_snaffle):

okay I need to restart matlab... It's not running any of the code in my command window

OpenStudy (phi):

I would use quotes around the filename load("weather_data")

OpenStudy (raffle_snaffle):

lol @phi thanks.

OpenStudy (raffle_snaffle):

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

OpenStudy (raffle_snaffle):

so when I load(weather_data) into my workspace it appears in the workspace as weatherdata without the _

OpenStudy (raffle_snaffle):

Reference to a cleared variable weatherdata. Error in lab02 (line 8) m = weatherdata(month,:); % extract months data

OpenStudy (phi):

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

OpenStudy (phi):

what do you get after loading the file? can you post the result of whos ?

OpenStudy (raffle_snaffle):

>> whos Name Size Bytes Class Attributes month 1x1 8 double >>

OpenStudy (phi):

no weather data? try to load it and do whos again

OpenStudy (raffle_snaffle):

>> whos weatherdata Name Size Bytes Class Attributes weatherdata 12x31 2976 double

OpenStudy (phi):

do you do a clear *after* the load? that is a bad idea you want to do the clear then load the data

OpenStudy (raffle_snaffle):

>> clear >> load('weather_data') >> whos weatherdata Name Size Bytes Class Attributes weatherdata 12x31 2976 double

OpenStudy (phi):

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

OpenStudy (raffle_snaffle):

okay got it

OpenStudy (raffle_snaffle):

okay it runs well so far. I am going to finish putting in the rest of the commands.

OpenStudy (raffle_snaffle):

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

OpenStudy (raffle_snaffle):

I had to fix a few things

OpenStudy (raffle_snaffle):

hold up for a sec. I need to read up on the command find and command length

OpenStudy (raffle_snaffle):

>> A = [1 4 12 0 9 2]; >> find(A) ans = 1 2 3 5 6

OpenStudy (raffle_snaffle):

in our case we were telling find what to do? find(m == m_max); find the month with the max rainfall?

OpenStudy (phi):

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

OpenStudy (raffle_snaffle):

|dw:1460510838427:dw|

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!