Size mismatching using "find" command
조회 수: 1 (최근 30일)
이전 댓글 표시
Hi everyone,
I'm experiencing some issues using the find command inside a for loop. I have a 28x230 matrix (mean_GMT_min_mean_ref); of every row, I want to detect the first time the value 2, when present, is reached. That is the problem. Given this code
for i=1:length(FileList)
y(i,1) = find((floor(mean_GMT_min_mean_ref(i,:))==2),1,'first');
value_2(i,1) = mean_GMT_min_mean_ref(i,y(i));
year_gwl_2(i,1) = x(y(i,1));
end
I get the error "Unable to perform assignment because the size of the left side is 1-by-1 and the size of the right side is 1-by-0." This because e.g. the second line of the matrix (and others) is made of values all < 2. I would just like, in the case that value isn't reached, to get a NaN in the column vector (y, value_2 and year_gwl_2 are all 28x1 vectors), instead of quitting the for loop with that annoying error.
Can anyone help me with this? Thanks in advance, Matteo
댓글 수: 0
채택된 답변
Voss
2022년 8월 12일
for i=1:length(FileList)
idx = find((floor(mean_GMT_min_mean_ref(i,:))==2),1,'first');
if isempty(idx)
y(i,1) = NaN;
value_2(i,1) = NaN;
year_gwl_2(i,1) = NaN;
else
y(i,1) = idx;
value_2(i,1) = mean_GMT_min_mean_ref(i,y(i));
year_gwl_2(i,1) = x(y(i,1));
end
end
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!