From: ravi gtg on
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
"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
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
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
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...

--
 |  Next  |  Last
Pages: 1 2
Prev: Convert 3D slice in matrix
Next: Matrix return values