Subscripted assignment dimension mismatch.

So I am working on a fingerprint thingy, not important. The thing is I am storing the position of the minutiae (ridges and valleys) in arrays.
I want to compare two fingerprint images.
totsfcvr1 is the matrix that stores the ridge position information for the first fingerprint.
totsfcvr2 is the matrix that stores the ridge position information for the second fingerprint.
I am converting those matrices to vectors and I am trying to add zeros so the dimension is the same for the both vectors for an easier comparison.
C = totsfcvr1';
C = C(:)';
D = totsfcvr2';
D = D(:)';
if size(D) >= size(C)
F = size(D)-size(C);
F(F==0) = [];
if size(D) == 1
G = [1];
else
G = size(D);
G(G==1) = [];
end
H = zeros(1,G);
H(1,1:G-F) = C;
C = H;
else
F = size(C)-size(D);
F(F==0) = [];
if size(C) == 1
G = [1];
else
G = size(C);
G(G==1) = [];
end
H = zeros(1,G);
H(1,1:G-F) = D;
D = H;
end
I get this error:
Subscripted assignment dimension mismatch.
at this line:
Error in main_GUI>verificare_Callback (line 151)
H(1,1:G-F) = C;

 Respuesta aceptada

James Tursa
James Tursa el 8 de Jun. de 2015
Editada: James Tursa el 8 de Jun. de 2015
You are using the size function to get at the number of elements, but the numel function is easier to use in this context. E.g.,
C = totsfcvr1';
C = C(:)';
D = totsfcvr2';
D = D(:)';
Cn = numel(C);
Dn = numel(D);
n = max(Cn,Dn);
C(Cn+1:n) = 0;
D(Dn+1:n) = 0;
In the above code, at most one of the last two lines will actually do anything (extend the vector with 0's). The other line will have a 2nd index less than the 1st index and do nothing to the vector. The extension code works because indexing beyond the current length of a vector on the left-hand-side will cause MATLAB to automatically increase the size of the vector to accommodate the assignment.

1 comentario

Graur Alin
Graur Alin el 8 de Jun. de 2015
Thank you, it works.
I am new to MatLab and, as you can see, I still have that "C++ vibe".

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Preguntada:

el 8 de Jun. de 2015

Editada:

el 8 de Jun. de 2015

Community Treasure Hunt

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

Start Hunting!

Translated by