Matlab 2D-Array indexing and replacing -
given array array_in of size m*n , r of size s*2. each row in array r corresponds starting , ending values of first column of array_in , corresponding column elements in array_in i.e array_in(:,2:end) should not changed , remaining elements replaced nan. first column of output array_out same array_in. number of rows of array r changes. in following example number of rows assumed 2.
array_in = [0 0.1;1 0.8;2 0.5;3 0.2;4 0.3;5 0.6;6 0.8;7 1;8 1.2;9 1;10 0.1]; r = [2 3;6 9];
r 1st row: should considered 2:3 = [2 3]; r 2nd row: 6:9 = [6 7 8 9]; rows i.e [2 3 6 7 8 9] should retained , , expected output is:
array_out = [0 nan;1 nan;2 0.5;3 0.2;4 nan;5 nan;6 0.8;7 1;8 1.2;9 1;10 nan];
how can done?
ind = ~any( bsxfun(@ge, array_in(:,1).', r(:,1)) & ... bsxfun(@le, array_in(:,1).', r(:,2)) ); array_out = array_in; array_out(ind,2:end) = nan;
Comments
Post a Comment