Remove empty sets in iteration to avoid indexing error?

1 vue (au cours des 30 derniers jours)
Andrew Poissant
Andrew Poissant le 5 Sep 2017
Modifié(e) : Stephen23 le 5 Sep 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

Réponse acceptée

Stephen23
Stephen23 le 5 Sep 2017
Modifié(e) : Stephen23 le 5 Sep 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.

Plus de réponses (0)

Catégories

En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by