problems with the step size in a for loop
Show older comments
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 Comment
Manoj
on 17 Nov 2014
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 ?
Accepted Answer
More Answers (1)
Thorsten
on 17 Nov 2014
Allocate Q to be a vector of 10 NaNs (not a number) before doing the computations
Q = nan(1,10);
Categories
Find more on Creating and Concatenating Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!