Replacing the column of array elements with NaN.
Afficher commentaires plus anciens
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?
Réponse acceptée
Plus de réponses (3)
Andrei Bobrov
le 29 Mai 2014
Out_Arr = A;
Out_Arr(all(bsxfun(@lt,A(:,1),x(:,1)')|bsxfun(@gt,A(:,1),x(:,2)'),2),2) = nan;
Udit Gupta
le 29 Mai 2014
0 votes
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 commentaires
pr
le 29 Mai 2014
Udit Gupta
le 29 Mai 2014
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.
Catégories
En savoir plus sur Creating and Concatenating Matrices dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!