Reputation: 37
For instance I have this matrices:
A = [ 1 2 3 4; 5 6 7 8; 9 10 2 12];
B = [5 4 3 2; 6 7 8 9; 10 9 1 7];
C = B.*A
the result is like this:
C = [5 8 9 8; 30 42 56 72; 90 90 2 84]
In my actual matrix the size of A and B varies.
My question is how do i find the minimum value from matrix C so the output will just be like this (from the result above):
C = 2
A = 2
B = 1
So basically, I need help with the code so matlab will find the minimum then return the value from matrices A and B that produce that minimum value.
Thank you!!
Upvotes: 0
Views: 143
Reputation: 9864
Second output argument of min
returns the index.
[C, I] = min(C(:));
A = A(I);
B = B(I);
Note that if there are more than one element that are equal to minimum the first one in C(:)
will be returned.
Upvotes: 5