フィルターのクリア

Simple Counter Problem using (i+1)

1 回表示 (過去 30 日間)
bugatti79
bugatti79 2014 年 7 月 19 日
回答済み: Jan 2014 年 7 月 19 日
Hi Folks,
I have an excel 1 column 906 rows which i call into this script. I want to get the difference between the i+1 row and the ith row, ie B6-B5, B7-B6 all the way down the column. The problem is when i run into the last row i get the following error
"??? Attempted to access t(907); index out of bounds because numel(t)=906."
I suspect this is a classical problem with counters but i dont know a workaround. Thanks
Here is my script. The problem is the 2nd line "dt"
for i=1:906;
dt(i+1)=t(i+1)-t(i);
dT(i)=dt(i+1)*(P_loss(i)-h*As*(T_Oil(i)-T_amb(i)))/(ma*Cp);
T_final(i)=(T_Oil(i)+dT(i));
end

採用された回答

Azzi Abdelmalek
Azzi Abdelmalek 2014 年 7 月 19 日
change your for loop
for i=1:906-1;

その他の回答 (1 件)

Jan
Jan 2014 年 7 月 19 日
Or more Matlabish without a loop:
dt = diff(t);
dT = dt .* (P_loss(1:905) - h*As*(T_Oil(1:905) - T_amb(1:905))) ./ (ma*Cp);
T_final = T_Oil(1:905) + dT;

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by