Remove empty sets in iteration to avoid indexing error?

1 visualización (últimos 30 días)
Andrew Poissant
Andrew Poissant el 5 de Sept. de 2017
Editada: Stephen23 el 5 de Sept. de 2017
I have a for loop and inside I have a find function. I am receiving a "Subscripted assignment dimension mismatch" error. After looking more it is because there are some empty sets in row(i) and col(i) causing that error. How do I set up a counter to tell matlab that if it encounters an empty set to just skip that iteration? I tried what is shown below but I am getting the error mentioned above. Can anyone help me with the logic of how to set this counter up? FGIF is a 936x2 matrix and N_new is a 884x884x3 matrix.
[FGIF_r, FGIF_c] = size(FGIF_m);
tol = 5;
for i = 1:FGIF_r
[row(i), col(i)] = find(abs(N_new(:,:,2) - FGIF_m(i,1)) <= tol & abs(N_new(:,:,3) - FGIF_m(i,2)) <= tol);
if isempty(row(i)) | isempty(col(i))
continue
end
end

Respuesta aceptada

Stephen23
Stephen23 el 5 de Sept. de 2017
Editada: Stephen23 el 5 de Sept. de 2017
  1. Put find's outputs into two temporary variables.
  2. Use an if to check if the variables are empty of not, and...
  3. inside the if assign the non-empty temporary variables to your arrays.

Más respuestas (0)

Categorías

Más información sobre Creating and Concatenating Matrices 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