Prev: Convert 3D slice in matrix
Next: Matrix return values
From: ravi gtg on 27 Jul 2010 20:28 Hello guys, I'd like some help, If I have a matrix A: A = [ 0 0 0 0 0; 0 0 0 0 2; 0 2 0 0 0; 0 0 0 0 0 ] now, the number 2 starts at column 2 and ends at column 5 also, the number 2 starts at row 2 and ends at row 3. So, I want to output a matrix with these starting and ending values in the following format: [ starting_row starting_column ending_row ending_column] So, for example, for matrix A, I'd like to get: [ 2 2 3 5] How can I do this? Thanks ravi
From: Judy on 27 Jul 2010 20:38 "ravi gtg" <ravi_071(a)hotmail.com> wrote in message <i2ntik$kb4$1(a)fred.mathworks.com>... > Hello guys, I'd like some help, > > If I have a matrix A: > > A = [ 0 0 0 0 0; > 0 0 0 0 2; > 0 2 0 0 0; > 0 0 0 0 0 ] > > > now, the number 2 starts at column 2 and ends at column 5 > > also, the number 2 starts at row 2 and ends at row 3. > > > So, I want to output a matrix with these starting and ending values in the following format: > > [ starting_row starting_column ending_row ending_column] > > > So, for example, for matrix A, I'd like to get: > > [ 2 2 3 5] > > How can I do this? > > Thanks > ravi Try this: [r,c]=find(A==2) then configure r and c however you want.
From: ravi gtg on 27 Jul 2010 21:35 hi Assuming, I have more 2's as follows in the A matrix and make the matrix more complex: A = [ 0 0 0 0 0; 0 0 2 2 2; 0 2 2 2 0; 0 0 0 0 0 ] If I use [r,c]=find(A==2) , I get for all positions of 2m which i do not want, I only want the values of first and last extents of the matrix ,i.e values for only starting and ending columns and rows. thanks ravi "Judy " <sauwen.jl(a)gmail.com> wrote in message <i2nu5a$qui$1(a)fred.mathworks.com>... > "ravi gtg" <ravi_071(a)hotmail.com> wrote in message <i2ntik$kb4$1(a)fred.mathworks.com>... > > Hello guys, I'd like some help, > > > > If I have a matrix A: > > > > A = [ 0 0 0 0 0; > > 0 0 0 0 2; > > 0 2 0 0 0; > > 0 0 0 0 0 ] > > > > > > now, the number 2 starts at column 2 and ends at column 5 > > > > also, the number 2 starts at row 2 and ends at row 3. > > > > > > So, I want to output a matrix with these starting and ending values in the following format: > > > > [ starting_row starting_column ending_row ending_column] > > > > > > So, for example, for matrix A, I'd like to get: > > > > [ 2 2 3 5] > > > > How can I do this? > > > > Thanks > > ravi > > Try this: > > [r,c]=find(A==2) > > then configure r and c however you want.
From: Matt Fig on 27 Jul 2010 21:46 Don't top post. A little thought will show that r = [min(r) max(r)] c = [min(c) max(c)] I am sure you could have come up with that one on your own!
From: dpb on 27 Jul 2010 21:44
ravi gtg wrote: .... > If I use [r,c]=find(A==2) , I get for all positions of 2m which i do not > want, I only want the values of first and last extents of the matrix .... Those would be min/max of r,c respectively... -- |