How to subtraction two matrix with different dimensions?

5 visualizaciones (últimos 30 días)
Veronika
Veronika el 11 de Abr. de 2017
Respondida: Walter Roberson el 22 de Abr. de 2017
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 comentarios
Veronika
Veronika el 16 de Abr. de 2017
I can´t accept the answer, I didn´t see this option.
the cyclist
the cyclist el 20 de Abr. de 2017
Oh, right. I forgot this all transpired through comments, and not an actual answer. Well, just advice for next time, then.

Iniciar sesión para comentar.

Respuestas (1)

Walter Roberson
Walter Roberson el 22 de Abr. de 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.

Community Treasure Hunt

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

Start Hunting!

Translated by