필터 지우기
필터 지우기

Dimension mismatch - saving output from a for loop

조회 수: 1 (최근 30일)
Bran
Bran 2015년 2월 17일
편집: per isakson 2015년 2월 17일
Just a straight forward question;
I am running a basic for loop;
TT = length of some vector;
for i = 2:TT
SS = Section1X(yy(i-1):yy(i));
AB =find(SS<=(0.9664*9.81*0.95));
if numel(AB)>0
NEW(i)=yy(i-1);
end
end
I want to store the values of AB on each loop and when I changed the code to AB(i,:) = find(SS..etc.) I get a dimension mismatch error.

답변 (2개)

per isakson
per isakson 2015년 2월 17일
편집: per isakson 2015년 2월 17일
The problem might be that find returns vectors, the length of which varies with i
Repolace
AB(i,:) = find(SS..etc.)
by
AB{i,:} = find(SS..etc.)
Another approach
dbstop if error
and inspect the variables involved
  댓글 수: 2
per isakson
per isakson 2015년 2월 17일
편집: per isakson 2015년 2월 17일
Copied to here by per isakson
I get the following error from this approach
??? Cell contents assignment to a non-cell array object.
Error in ==> METRICSFINAL2 at 177
AB{i,:} =find(SS<=(0.9664*9.81*0.95));
per isakson
per isakson 2015년 2월 17일
편집: per isakson 2015년 2월 17일
My mistake. Should read
AB{i} =find(SS<=(0.9664*9.81*0.95));

댓글을 달려면 로그인하십시오.


Bran
Bran 2015년 2월 17일
I get the following error from this approach
??? Cell contents assignment to a non-cell array object.
Error in ==> METRICSFINAL2 at 177
AB{i,:} =find(SS<=(0.9664*9.81*0.95));

카테고리

Help CenterFile Exchange에서 Mathematics에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by