2017-05-13 1 views

Antwort

0

Ich nehme an, dass Ihre Matrixeinträge Positionseinträge sind? Wenn nicht, erstellen Sie zwei Matrizen x und y mit der Größe Ihrer 2D-Matrix und nehmen Sie sie als Referenz.

% create matrix 
[x,y] = meshgrid(1:50); 

% cropped matrix 
x_crop = x(20:45,10:30); 
y_crop = y(20:45,10:30); 

% position in full-size matrix 
pos = [25, 23]; % [x-coordinate, y-coordinate] 

% get minimum and maximum positions of x_crop and y_crop 
xmin = min(x_crop(:)); 
xmax = max(x_crop(:)); 

ymin = min(y_crop(:)); 
ymax = max(y_crop(:)); 

% Check if pos is inside minima/maxima 
if pos(1)>= xmin && pos(1)<= xmax && pos(2)>=ymin && pos(2)<=ymax 
    is_in = true; 
else 
    is_in = false; 
end 

is_in 

Hoffe, dass hilft. Hoffe auch, ich habe deine Frage verstanden: D

Verwandte Themen