How to avoid a numerical problem in a for loop
이전 댓글 표시
I have two input files T and dispatch_seq. My code looks at T and sees how many rows of dispatch_seq should be taken. The result is stored in Output.
load T.mat
load dispatch_seq.mat
for j = 1:length(T)
ph1 = cumsum(cell2mat(dispatch_seq{j}(:,2)));
DecR1 = 10*rem(ph1,1);
for k = 1:length(ph1)
if DecR1(k) <= 0.1
ph1(k) = round(ph1(k));
end
end
j_1 = find(ph1>=T(j),1);
Output(j) = {dispatch_seq{j}(1:j_1,:)};
if ph1(j_1) > T(j)
Output{j}{end,2} = (Output{j}{end,2}-ph1(j_1)+T(j));
end
end
Everything works as expected with the exception of Output{28,1} and Output{77,1}. What happens there is the number in the corresponding row of the vector T equals exactly the sum of all rows of dispatch_seq, but the result I get in Output is []. How can I avoid this error?
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!