How to use If function to choose just some values of the matrix?

1 vue (au cours des 30 derniers jours)
Beibit Sautbek
Beibit Sautbek le 1 Juil 2016
Modifié(e) : KSSV le 1 Juil 2016
I have 10 points with x and y axis which is represented in matrix C: C =
11.1902 78.9215
43.7123 84.8152
26.2182 55.0542
89.4285 18.3821
41.1215 32.8977
62.8533 101.3337
26.5649 25.2378
70.1982 92.5817
36.2971 63.8342
75.4079 109.6135
The first column represents x axis, and second column indicates y axis.
I need to set conditions like:
If x positions of any 10 points is less than 5 or more than 60 (5>x>60),
cancel that point (x,y) from the matrix.
Actually I tried like this, but something is wrong:
if length(find(C(:,1)<5| C(:,1)>60))~=0
end
At the end results should be like this: C =
11.1902 78.9215
43.7123 84.8152
26.2182 55.0542
41.1215 32.8977
26.5649 25.2378
36.2971 63.8342

Réponse acceptée

KSSV
KSSV le 1 Juil 2016
Modifié(e) : KSSV le 1 Juil 2016
C = [11.1902 78.9215
43.7123 84.8152
26.2182 55.0542
89.4285 18.3821
41.1215 32.8977
62.8533 101.3337
26.5649 25.2378
70.1982 92.5817
36.2971 63.8342
75.4079 109.6135] ;
x = C(:,1) ; y = C(:,2) ;
idx = find(x<5 | x>60) ;
C(idx,:) = [];
C =
11.1902 78.9215
43.7123 84.8152
26.2182 55.0542
41.1215 32.8977
26.5649 25.2378
36.2971 63.8342

Plus de réponses (0)

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by