How to display the values from each iteration with while loop?
古いコメントを表示
I'm very new to matlab, and am trying to design a while loop then display the values from every iteration as a vector. Here's my code so far:
x = [45 38 47 41 35 43];
n = 2;
while n <= 6;
V = var(x(1:n));
n = n + 1;
V;
end
I would like to display the 5 values of V as a vector but can only seem to display the final one
thanks
1 件のコメント
Vivek
2013 年 2 月 21 日
instead of V = var(x(1:n)); write V(end+1)=var(x(1:n));
回答 (1 件)
Image Analyst
2013 年 2 月 21 日
編集済み: Image Analyst
2013 年 2 月 21 日
Try adding a loop counter
x = [45 38 47 41 35 43];
n = 2;
counter = 1;
while n <= 6;
V(counter) = var(x(1:n));
n = n + 1;
fprintf('Finished iteration #%d and V(%d) = %f\n',...
counter, counter, V(counter));
counter = counter + 1;
end
% Display all values of V:
V
カテゴリ
ヘルプ センター および 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!