Restricting matrix values
Mostrar comentarios más antiguos
I have a matrix:
points=
37 29
36 30
37 30
35 31
36 31
37 31
36 32
37 32
46 58
I need to restrict the values of the points such that
26<points(:,1)<46
21<points(:,2)<41
I want to remove the entire column if the above condition is not held.
E.g: (46,58) at position 9 is outside the boundaries, so I want points(9,:)=[]
I have written a very roundabout way of doing this:
find1=find(points(:,1)<(26))
if ~isempty(find1)
for i=1:length(find1)
points(find1(i),:)=[];
end
end
find2=find(points(:,1)>(46))
if ~isempty(find2)
for i=1:length(find2)
points(find2(i),:)=[];
end
end
find3=find(points(:,2)<(21))
if ~isempty(find3)
for i=1:length(find3)
points(find3(i),:)=[];
end
end
find4=find(points(:,2)>(41))
if ~isempty(find4)
for i=1:length(find4)
points(find4(i),:)=[];
end
end
However this method breaks if for a position "pos" points(pos,1) and points(pos,2) both exceed boundaries.
Does anyone have a cleaner way of doing this?
Thank you in advance for your responses!
2 comentarios
Sean de Wolski
el 15 de Ag. de 2011
Entire column or entire row?
A
el 15 de Ag. de 2011
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Logical en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!