Prev: uicontol callback
Next: Irregular fourier matrix
From: Evan on 12 Jul 2010 15:59 Say I have a matrix Test = [1,2,3,4; 5,6,7,8]; And two arrays corresponding to the rows and columns of points I'd like to set to zero in the matrix Test. Rows = [1,2]; Cols = [3, 1]; Is there any way to use a single line of code (I'm trying to avoid loops) to set the positions (1,3) and (2,1) in the matrix Test to 0? Something like Test(Row, Cols) = 0; that doesn't change four values in Test? Is it possible to limit the indexing into Cols to be just once per Row? Seems like I must be missing something simple... Thanks!
From: Evan on 12 Jul 2010 16:13 Nevermind, seems I should use sub2ind. Can't seem to find a way to delete this messgae...
From: us on 12 Jul 2010 16:52 "Evan " <Evan(a)fake.com> wrote in message <i1fs6p$2l8$1(a)fred.mathworks.com>... > Say I have a matrix > > Test = [1,2,3,4; > 5,6,7,8]; > > And two arrays corresponding to the rows and columns of points I'd like to set to zero in the matrix Test. > > Rows = [1,2]; > Cols = [3, 1]; > > Is there any way to use a single line of code (I'm trying to avoid loops) to set the positions (1,3) and (2,1) in the matrix Test to 0? > > Something like Test(Row, Cols) = 0; that doesn't change four values in Test? Is it possible to limit the indexing into Cols to be just once per Row? Seems like I must be missing something simple... > > Thanks! a hint: help sub2ind; us
|
Pages: 1 Prev: uicontol callback Next: Irregular fourier matrix |