Borrar filtros
Borrar filtros

What's wrong with my for loop?....error is that matric dimensions must match.

1 visualización (últimos 30 días)
Bii=B1{ii};
for ii= 1:N
Bii=B1{ii};
[x,y]=find(B1{ii}==max(max(B1{ii})));
[X,Y]=find(B1{1}==max(max(B1{1})));
DIFF=[x,y]-[X,Y]
end
.....basically I'm assigning images to a matrix Bii....each image is an element of the matrix...and I'm trying to find the x,y coordinates of the brightest spot on each image and subtracting that of the first frame from each of them...
IT SAYS ERROR IN USING - (the minus sign)...MATRIX DIMENSIONS MUST AGREE.
  2 comentarios
Yagnaseni Roy
Yagnaseni Roy el 22 de Oct. de 2011
Note that this is supposed to be a modification of the following code that does work...
Bii=B1{ii};
for ii= 1:N
Bii=B1{ii};
[x,y]=find(B1{ii}==max(max(B1{ii})));
[x,y]=find(B1{ii}==max(max(B1{ii})))
end

Iniciar sesión para comentar.

Respuesta aceptada

Fangjun Jiang
Fangjun Jiang el 22 de Oct. de 2011
The constructed matrix [x,y] and [X,Y] don't have the same size so you can't do subtraction. see
rand(3,1)-rand(2,4)
  29 comentarios
Yagnaseni Roy
Yagnaseni Roy el 24 de Oct. de 2011
yeah! But then all's well that ends well...hopefully this should bring an end to my project too...hope he doesn't ask me to modify it too much!!
Walter Roberson
Walter Roberson el 24 de Oct. de 2011
I did say hours ago that the code shown had no outputs. You were overwriting [x,y] each pass through the loop, and you were not doing anything calculated indices.
Memo for future reference: anything that appears un-indexed on the left-hand side of an assignment in a "for" loop will be overwritten on the next iteration. If you want the results to be saved for after the loop, you need an indexed assignment at some point in the loop.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by