フィルターのクリア

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 Center および File ExchangeMathematics についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by