Prev: cell array
Next: ginput, MatLAB GUI
From: Juan Jose on 23 Jul 2010 00:52 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 23 Jul 2010 05:52 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 23 Jul 2010 06:44 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 23 Jul 2010 09:05 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 24 Jul 2010 13:58 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 |