How to subtraction two matrix with different dimensions?

1 view (last 30 days)
Dear all,
I have two matrix. thisBoundary1=1232x2double and thisBoundary2=1237x2double. And I would like to subtraction these two like :
dech = thisBoundary2 - thisBoundary1
But I have this error:
Error using -
Matrix dimensions must agree.
Error in dechova_krivka (line 74)
dech = thisBoundary2 - thisBoundary1
Can you please help me, how to modify these two matrix for subtraction?
  9 Comments
Veronika
Veronika on 16 Apr 2017
I can´t accept the answer, I didn´t see this option.
the cyclist
the cyclist on 20 Apr 2017
Oh, right. I forgot this all transpired through comments, and not an actual answer. Well, just advice for next time, then.

Sign in to comment.

Answers (1)

Walter Roberson
Walter Roberson on 22 Apr 2017
One approach that calculates the portion that is inside both regions:
load thisBoundary1
load thisBoundary2
maxdim = max([thisBoundary1(:); thisBoundary2(:)]);
reg1 = poly2mask( thisBoundary1(:,1), thisBoundary1(:,2), maxdim, maxdim );
reg2 = poly2mask( thisBoundary2(:,1), thisBoundary2(:,2), maxdim, maxdim );
both_reg = reg1 & reg2;
A different approach is to use https://www.mathworks.com/matlabcentral/fileexchange/22441-curve-intersections to find the intersections of the regions and then do something with that intersection information. You would use this in the situation where you needed to calculate the intersections as exactly as feasible. Your coordinates appear to all be integers, so I doubt you need this.
A third approach that calculates the area that is inside either region is:
load thisBoundary1
load thisBoundary2
x = [thisBoundary1(:,1); thisBoundary2(:,1)];
y = [thisBoundary1(:,2); thisBoundary2(:,2)];
k = boundary(x, y);
plot(x(k), y(k))
A fourth approach would be to use image registration techniques to align the two for best match before doing one of the techniques described above.

Categories

Find more on Graphics Object Programming in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!