Remove empty sets in iteration to avoid indexing error?

1 Ansicht (letzte 30 Tage)
Andrew Poissant
Andrew Poissant am 5 Sep. 2017
Bearbeitet: Stephen23 am 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

Akzeptierte Antwort

Stephen23
Stephen23 am 5 Sep. 2017
Bearbeitet: Stephen23 am 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.

Weitere Antworten (0)

Kategorien

Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by