From: Bruce Bowler on 19 Jul 2010 13:51 I would have thought this little snippet would have worked to set a subset of an array to nan, but it didn't... I know I can do it with a loop, but is there a "better way"? array(abs(array(:,3:11))>threshold,3:11) = nan; Basically if the absolute value of an element in columns 3 thru 11 is greather than some threshold, set it to nan. Thanks! Bruce -- +-------------------+---------------------------------------------------+ Bruce Bowler | No man has a good enough memory to make a 1.207.633.9610 | successful liar. bbowler(a)bigelow.org | - Abraham Lincoln +-------------------+---------------------------------------------------+
From: Wayne King on 19 Jul 2010 14:06 Bruce Bowler <bbowler(a)bigelow.org> wrote in message <8ajhl6F7b3U1(a)mid.individual.net>... > I would have thought this little snippet would have worked to set a > subset of an array to nan, but it didn't... I know I can do it with a > loop, but is there a "better way"? > > array(abs(array(:,3:11))>threshold,3:11) = nan; > > Basically if the absolute value of an element in columns 3 thru 11 is > greather than some threshold, set it to nan. > > Thanks! > Bruce > > -- > +-------------------+---------------------------------------------------+ > Bruce Bowler | No man has a good enough memory to make a > 1.207.633.9610 | successful liar. > bbowler(a)bigelow.org | - Abraham Lincoln > +-------------------+---------------------------------------------------+ Hi Bruce, one of many ways. A = randn(10,12); B = A(:,3:11); Thresh = 1.5; B(abs(B)>1.5) = NaN; A(:,3:11) = B; Wayne
From: Sean on 19 Jul 2010 14:18 Bruce Bowler <bbowler(a)bigelow.org> wrote in message <8ajhl6F7b3U1(a)mid.individual.net>... > I would have thought this little snippet would have worked to set a > subset of an array to nan, but it didn't... I know I can do it with a > loop, but is there a "better way"? > > array(abs(array(:,3:11))>threshold,3:11) = nan; > > Basically if the absolute value of an element in columns 3 thru 11 is > greather than some threshold, set it to nan. > 1.207 To a fellow Mainer! One way: array = magic(20); threshold = 30; start_col = 3; end_col = 11; idx = find(abs(array(:,start_col:end_col))>threshold)+(start_col-1)*size(array,1); %convert local idx to global idx with addition at end array(idx) = nan;
|
Pages: 1 Prev: help with matlab code Next: Need to read large video files into Matlab |