From: Juan Jose on
Given a matrix m, where m=ones(y,x).
let us have a random integer, w, be generated from the interval 1 to y*x

¿How can i determine the [col row] position the element m(w)?
From: Jan Simon on
Dear Juan,

> Given a matrix m, where m=ones(y,x).
> let us have a random integer, w, be generated from the interval 1 to y*x
>
> ¿How can i determine the [col row] position the element m(w)?

1. help sub2ind
2. Usually you can use the linear index directly:
X = rand(3, 4);
disp(X(7))

Good luck, Jan
From: Nic Roberts on
Hi,

You can just clock through the matrix until you find the element you are looking for

eg

s=size(m)
for i:s(1)
for j:s(2)
if m(i,j) = <your value>
pos=[i j];
end
end
end

end

Hope that helps

Nic

"Jan Simon" <matlab.THIS_YEAR(a)nMINUSsimon.de> wrote in message <i2boo5$pjo$1(a)fred.mathworks.com>...
> Dear Juan,
>
> > Given a matrix m, where m=ones(y,x).
> > let us have a random integer, w, be generated from the interval 1 to y*x
> >
> > ¿How can i determine the [col row] position the element m(w)?
>
> 1. help sub2ind
> 2. Usually you can use the linear index directly:
> X = rand(3, 4);
> disp(X(7))
>
> Good luck, Jan
From: Jan Simon on
Dear Nic,

> s=size(m)
> for i:s(1)
> for j:s(2)
> if m(i,j) = <your value>
> pos=[i j];
> end
> end
> end

Take a look at the command FIND.
Jan
From: Nic Roberts on
Thanks Jan, wasnt aware of this.

Nic

"Jan Simon" <matlab.THIS_YEAR(a)nMINUSsimon.de> wrote in message <i2c424$ich$1(a)fred.mathworks.com>...
> Dear Nic,
>
> > s=size(m)
> > for i:s(1)
> > for j:s(2)
> > if m(i,j) = <your value>
> > pos=[i j];
> > end
> > end
> > end
>
> Take a look at the command FIND.
> Jan
 | 
Pages: 1
Prev: cell array
Next: ginput, MatLAB GUI