How to use If function to choose just some values of the matrix?
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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
0 Kommentare
Akzeptierte Antwort
KSSV
am 1 Jul. 2016
Bearbeitet: KSSV
am 1 Jul. 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
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Logical finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!