problems with the step size in a for loop
이전 댓글 표시
Dear readers,
I'm fairly new to Matlab so i beg your pardon for asking what will possible be a rather simple question:
First of all my code:
R=150;
h(1) = 0.6 ;
for i=1:2:10
Q(i) = sqrt(h(i)/R)
h(i+2) = -Q(i)*dT+h(i);
end
My problem is that when i look at the values of Q, it contains a lot of zeros. I realised that those must be values of the even i numbers ( Q(2), Q(4), Q(6) etc. ). My questions are: Why are those filled in as a zero, while i am not defining them at all. and how can i fix this? What i want is that the even i numbers do not have a Q value at all.
댓글 수: 1
Manoj
2014년 11월 17일
I am not sure how you are calculating Q in the first place, because both h and R are single values. How do you want them to change in the loop to get an array of Q values ?
채택된 답변
추가 답변 (1개)
Thorsten
2014년 11월 17일
Allocate Q to be a vector of 10 NaNs (not a number) before doing the computations
Q = nan(1,10);
카테고리
도움말 센터 및 File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!