Access Matrix using array as keys

3 Ansichten (letzte 30 Tage)
James kivai
James kivai am 25 Jun. 2021
Beantwortet: Walter Roberson am 26 Jun. 2021
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?

Antworten (1)

Walter Roberson
Walter Roberson am 26 Jun. 2021
sub2ind()

Kategorien

Mehr zu Matrices and Arrays 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!

Translated by