Remove empty sets in iteration to avoid indexing error?

1 次查看(过去 30 天)
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

采纳的回答

Stephen23
Stephen23 2017-9-5
编辑:Stephen23 2017-9-5
  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.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by