Unsure of how to use and understand rand function
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
This is for an Intro to Matlab Course I have to take.
the instructions state to use the rand function, create an array called A of size 1000 by 1000.
So i think it would be done by "A= RAND(1000,1000)
It then says:
Imagine that this array is made of up 4 500X500 arrays corresponding to the upper left
array, upper right array, lower left array, and lower right array. Using the appropriate
function calls,find the mean, median, and standard deviation of the elements making up
each of these four arrays. Report and comment on these values in your response section.
(Hint: read through the documentation for each of these functions. If you these functions a
2D array, what will the dimensions of the output be? You will likely want to use the
reshape() function in conjunction with median and standard deviation).
And I have NO CLUE what to do right here. Can anyone help me out, and guide me in a direction?
0 Kommentare
Antworten (3)
Image Analyst
am 10 Feb. 2014
Hint:
subArray = array(row1:row2, column1:column2);
meanOfSubArray = mean(subArray(:));
I imagine you know what row1, row2, column1, and column2 would be. For row2 and column2 being at the end, you can use "end" instead of 1000, e.g
subArray = array(501:end, 501:end);
2 Kommentare
Image Analyst
am 10 Feb. 2014
I didn't say that. I said you could set column2 to be 1000 or "end" when you are indexing, specifically the right half. OK, another major hint . Here is how to get the upper right part of the array
upperRight = A(1:500, 501:end)
meanOfUpperRight = mean(upperRight(:));
The code to get the means of the other quadrants is very similar.
Jos (10584)
am 10 Feb. 2014
It is always insightful to look at a smaller example:
A = [ 4 2 3 1 ; 5 4 2 3 ; 6 7 8 9 ; 1 4 2 5] % just 2-by-2 instead of 1000-by-1000
B = A(1:2,3:4) % which quadrant of A is now stored in B?
C = B(:) % how this does change the contents from B?
mean(C)
0 Kommentare
Iain
am 10 Feb. 2014
A= RAND(1000,1000)
Does like you think. It creates a 1000 x 1000 matrix.
The rest of the problem is trying to get you to think of a matrix just a table, a table which can be split up arbitrarily. A 3 x 3 table could be split up into 3, 1 x 3 vectors. A 4 x 4 table could be split up into 4, 2x2 tables.
It is telling you to split up a 1000 x 1000 into 4 500x500 tables.
It is then telling you to calculate the mean, median, and standard deviation of each of those 4 sections. e.g.
a_split_up_bit = A( 4:5,3:9);
Takes the 4th and 5th rows, on the 3rd to 9th columns, and puts them in a_split_up_bit as a 2x7 table.
"mean" (median/std, min, max, etc.) calculates the mean (mediant/standard deviation, min, max, etc) for any vector, not a table. It calculates the mean of each column in a table.
Reshape allows you to copy & reshape a table into a vector, or another, differently sized table.
0 Kommentare
Siehe auch
Kategorien
Mehr zu Matrices and Arrays finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!