Finding corners of a matrix inside a matrix.

I have a matrix of size 50*80 which contains non-zero values in the center of matrix. for example-- I would like to extract the position of the corner elements in that matrix i.e position of (0,0,5,7) elements. Can anyone help me with the code?
A=[0 0 0 0 0 0 0 0 ;
0 0 0 2 4 5 0 0;
0 0 4 0 5 2 1 0;
0 0 5 8 7 6 7 0;
0 0 0 0 0 0 0 0;
end

 Risposta accettata

[r,c]=find(A~=0);
upperLeft=A(min(r),min(c))
lowerLeft=A(max(r),min(c))
upperRight=A(min(r),max(c))
lowerRight=A(max(r),max(c))

6 Commenti

Thank you for the solution but I want the position of the corners i.e row & column number of the corner elements.
@Swapnil Rane: that is what Birdman showed you: min(r),min(c), etc.
I don't get it. The output should give me the row & column number i.e upper left=[2,3] lowerleft=[4,3] ...etc.
store it in a cell array maybe,
corners = {[min(r),min(c)],[min(r),max(c)];[max(r),min(c)],[max(r),max(c)]}
Stephen23
Stephen23 il 26 Feb 2018
Modificato: Stephen23 il 26 Feb 2018
upperLeft = [min(r),min(c)]
etc.
@KL and @Stephen Cobeldick, both of the code works for me.
Thank you, I really appreciate it.

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Mathematics in Centro assistenza e File Exchange

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by