フィルターのクリア

Subscripted assignment dimension mismatch. error is coming in array(k,1)=su; pls help me out??thanks 4 any help

2 ビュー (過去 30 日間)
su=0;k=1;
array=zeros(size(p,1),2);
j=1;
while(1)
for i=j:size(p,1)
if i>size(p,1)-1
array(k,1)=1;
array(k,2)=p(i,2);
break;
end
if p(i,2)==p(i+1,2)
su=su+p(i,1);
else
break
end
end
su=su+p(i,1);
array(k,1)=su;
array(k,2)=p(i,2);
j=i+1;
k=k+1;
su=0;
end

採用された回答

Walter Roberson
Walter Roberson 2013 年 4 月 25 日
We do not know size(p)
If p starts out empty then size(p,1) would be 0, and
for i = j:size(p,1)
would be for i = 1:0 which would leave i as being []. Then p(i,1) would be p([],1) which would be []; su = su + p(i,1) would be su = su + [] and that makes su = []. array(k,1) = su then becomes a dimension mismatch
  3 件のコメント
Sony
Sony 2013 年 4 月 26 日
the error is at array(k,1)=su; when i print su it shows Empty matrix: 0-by-1,the size of p is 10cross2,the size of su is 0cross1,pls help me with error i dnt knw how to proceed.
Walter Roberson
Walter Roberson 2013 年 4 月 26 日
When i reaches size(p,1), then j gets set to size(p,1)+1, and then the
for i=j:size(p,1)
becomes
for i=size(p,1)+1:size(p,1)
which does not execute the "for i" loop body and leaves i=[]. Then after the body of the for loop, the su=su+p(i,1) becomes su=su+p([],1) which get you su=[], leading to the failure on the next line.
Base problem: you do not have any "break" out of the "while(1)" loop so you eventually get past the end of p.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by