Adding and substracting elements from different arrays element wise and repeatedly
정보
이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.
이전 댓글 표시
Dear All
I'd like to do some operations between different arrays element wise and be able to repeat this a number of times.
This is my problem. I'm computing how much water is in a tank by doing as follows: (water available for the next hour in the tank) = (water stored in the tank this hour)+ (added water during this hour)- (water taken this hour (for irrigation))
I want to do this for a whole year and I now how much water is needed for every hour and how much I water I will add every hour. I also have a starting value for what's in the tank.
Tank = ones(8760,1);
Tank(1,1) = 10000;
for B = 2:8760;
Tank(B,1) = Tank(B-1,1)+ AddedWater(B-1,1) - Demand(B-1,1);
end
This does not work and does not really give an error message, it just says that the line where I do the math is faulty.. Anyone some advice?
Thanks in advance
Charles
댓글 수: 4
Julian Rosker
2017년 7월 5일
Would it be possible to run "size(AddedWater)" and "size(Demand)" just before the for loop and respond with those outputs?
Charles Colin
2017년 7월 5일
Julian Rosker
2017년 7월 5일
Demand actually looks fine, the problem seems to be in AddedWater. Since you are taking data for every hour other than the last one (one data point each iteration in the loop, from 1 to 8759 since you subtract 1 on your indexing variable), your AddedWater matrix should have at least 8759 data points. Ensure that AddedWater has the proper data and size, likely "8760 1", and try running again.
Charles Colin
2017년 7월 5일
답변 (1개)
Andrei Bobrov
2017년 7월 5일
Tank = [10000;ones(8759,1)];
Tank_out = cumsum(Tank + AddedWater - Demand);
댓글 수: 0
이 질문은 마감되었습니다.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!