フィルターのクリア

Info

この質問は閉じられています。 編集または回答するには再度開いてください。

how to do addition with in an array , save to another but condition is the sum of value in 2nd array should not less than or equal to 15.? and my program going to infinite loop..

1 回表示 (過去 30 日間)
preet
preet 2013 年 3 月 13 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
a=[2,14,23,12,4,4,10,1]
if there is any value in the array a() is less than or equal to 15 than that will add to next value of same array and store in the another array b(). each value in b() should be more than 15 at last if there is no value in the array a() and the addition is less than equal to 15 then the result of addition will add to the previous value to the array b().
a=[2,14,23,12,4,4,10,1];
index=1;i=1;
while (i<=8)
if(a(i)>15)
b(index)=a(i);
index=index+1;
else
value=a(i);
j=i;
while(value<=15)
if(j<8)
j=j+1;
value=value+a(j);
% j=j+1;
else
break;
end
end
i=j+1;
if(value>15)
b(index)=value;
index=index+1;
else
b(index)=b(index)+value;
end
end
end
and my answer after to implment it. infinite loop going on. my answer should be b=[31,23,16]
  6 件のコメント
preet
preet 2013 年 3 月 15 日
if a=[1,14,23,12,4,4,10,1]
then [15, 35,16] so should i add 15+35 or 15+16?
Cedric
Cedric 2013 年 3 月 15 日
編集済み: Cedric 2013 年 3 月 15 日
>> so should i add 15+35 or 15+16?
Well, it is up to you to perfectly know/define what you want to compute and how. Then we can help you writing MATLAB code (or improving it) for that.

回答 (0 件)

この質問は閉じられています。

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by