Access Matrix using array as keys
조회 수: 3 (최근 30일)
이전 댓글 표시
I have a matrix
allPoints = ["10999970X10999700Y" "11000310X12099960Y" "10999970X12999700Y";
"11999970X10999960Y" "11999970X12000230Y" "11999970X13000230Y";
"12999970X10999700Y" "12999970X12000230Y" "12999970X13000230Y"]
And I want to select points based of rectangles, where I have bottom and top points of the rectangle
For a single rectangle with
bottom = [1 1]; top = [2 2];
I would use:
coveredPoints = allPoints(bottom(1):top(1),bottom(2):top(2))
%% OUTPUT
% coveredPoints =
%
% 2×2 string array
%
% "10999970X10999700Y" "11000310X12099960Y"
% "11999970X10999960Y" "11999970X12000230Y"
which would return all the points from (1,1) to (2,2).
But now I have multiple bottoms and tops, and I want to get all the covered areas into a n x 1 array (single column array)
bottoms = [1 3; 2 2]; tops=[1 3; 2 2];
% When I try
coveredPoints = allPoints(bottoms(:,1):tops(:,1), bottoms(:,2):tops(:,2));
% It only returns the values for the first row only
% coveredPoints =
%
% "10999970X12999700Y"
Is there a way to extract all covered points onto a n x 1 array without a loop?
댓글 수: 0
답변 (1개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Matrices and Arrays에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!