How do I compare two similar sized matrices?

Hi all!
I have two 76x2000 matrices and I would like to compare them to see which one is always higher. What is the best way for me to go about this? A function that would allow me to put in different pairs would be most appreciated.
Thank you!

6 commentaires

Geoff Hayes
Geoff Hayes le 21 Août 2016
Lakyn - please clarify what you mean by to see which one is always higher. What does higher mean to you?
Lakyn
Lakyn le 21 Août 2016
Hi Geoff, Sorry for the late reply! Higher basically means higher in terms of the number, so e.g. 5 is higher than 3.
per isakson
per isakson le 22 Août 2016
Modifié(e) : per isakson le 22 Août 2016
is_higher = A > B;
is_higher = gt( A, B );
will return a&nbsp<76x2000 logical> array. Is that what you are looking for?
Lakyn
Lakyn le 22 Août 2016
Hi, what do you mean by a 76x2000 logical array? Would this help me to determine which of any two matrices have a higher value?
Thank you!
per isakson
per isakson le 22 Août 2016
Modifié(e) : per isakson le 22 Août 2016
"what do you mean by a 76x2000 logical array" &nbsp there is a good answer in the middle of Introducing MATLAB Fundamental Classes (Data Types)
I still don't fully understand what you mean by "matrices have a higher value". The example you provided above explains "higher" regarding scalars, not matrices. Please give a small example regarding matrices. See Norm (mathematics) and Vector and matrix norms.
Lakyn
Lakyn le 22 Août 2016
Thanks for the link! explains a lot.
Well, I think it can be said to mean that every single value in that matrix is higher than the corresponding one in the other matrix. So for example, 3rd row 80th column value of the first matrix is higher than the 3rd row 80th column value of the second matrix.

Connectez-vous pour commenter.

 Réponse acceptée

per isakson
per isakson le 22 Août 2016
Modifié(e) : per isakson le 22 Août 2016
"every single value in that matrix [ A ] is higher than the corresponding one in the other matrix [ B ]"
is_gt = A > B;
is_higher = all( is_gt(:) );
(:) is a trick to reshape a matrix to a column vector.

6 commentaires

Lakyn
Lakyn le 22 Août 2016
Hi,
thank you very much for the help! I tried to use the code, and if I read it correctly, if I get the resulting answer of is_higher = 0, it means that every value in A is NOT higher than the corresponding in B is that right?
per isakson
per isakson le 22 Août 2016
Modifié(e) : per isakson le 22 Août 2016
Yes, Matlab use the digit, 1, to display the logical value true and the 0 to display the logical value false. (The reason why is way back in the history of Matlab.) Thus, 1 shows that all elements of A are greater than corresponding elements of B.
To inspect the intermediate result use
imagesc( is_gt )
Lakyn
Lakyn le 22 Août 2016
ah thank you very much. This helps a lot!
What if I want to look at the average? Like say, if the average of every value in A is greater than the average of every value in B? Do I just replace every A and B with mean(A) and mean(B)?
per isakson
per isakson le 22 Août 2016
Modifié(e) : per isakson le 22 Août 2016
Ask Matlab itself. However, use
mean( A(:), 'omitnan' )
mean( B(:), 'omitnan' )
to returns scalars and be robust to NaNs. Or use "mean of mean"
mean(mean(A))
Lakyn
Lakyn le 22 Août 2016
interesting, thanks for that.
What if say, I want to compare just the 76 rows? Is there a way for me to average the 2000 columns to get a single value for each row, and then compare the two matrices?
Thank you so much! Sorry I keep asking questions haha
First, watch the video Working with Arrays in MATLAB carefully.
Secondly, try
is_gt = mean(A,1,'omitnan') > mean(B,1,'omitnan');
is_higher = all( is_gt(:) );

Connectez-vous pour commenter.

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by