Remove empty sets in iteration to avoid indexing error?

조회 수: 1 (최근 30일)
Andrew Poissant
Andrew Poissant 2017년 9월 5일
편집: Stephen23 2017년 9월 5일
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