Replacing the column of array elements with NaN.
显示 更早的评论
Given an array A = [0 11; 0.1 2; 0.2 5; 0.3 3; 0.4 6; 0.5 7; 0.6 10; 0.7 4; 0.8 5; 0.9 6; 1 12]; and array x = [0.2,0.4 ; 0.6,0.9];. I would like to manipulate the second column. with respect to the array x. Out_Arr = [0 NaN; 0.1 NaN; 0.2 5; 0.3 3; 0.4 6; 0.5 NaN; 0.6 10; 0.7 4; 0.8 5; 0.9 6; 1 NaN]; Could any one help on this?
采纳的回答
更多回答(3 个)
Andrei Bobrov
2014-5-29
Out_Arr = A;
Out_Arr(all(bsxfun(@lt,A(:,1),x(:,1)')|bsxfun(@gt,A(:,1),x(:,2)'),2),2) = nan;
Udit Gupta
2014-5-29
0 个投票
This should do the trick -
index1 = A(:,1)<x(1,1) | A(:,1)>x(1,2);
index2 = A(:,1)<x(2,1) | A(:,1)>x(2,2);
A(index1 & index2, 2) = NaN
2 个评论
pr
2014-5-29
Udit Gupta
2014-5-29
Put it in a loop and give replace x(1,1), x(1,2) etc. by x(i,1) and x(1,2). You can successively apply and (&) operator to the index and at the end of the loop perform the operation.
类别
在 帮助中心 和 File Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!