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!