Add to a vector from loop
古いコメントを表示
Team,
Just learning how to use MatLab here,
How do I insert the value n into a different variable so I can recall each number? Any other advice is much appreciated. I just started MATH240 so will need more help later ;)
-----------------------------------------------
totaln=0;
n=1;
for n=1:1000000;
if abs(cos(n))<1/n;
totaln=totaln+1;
display(n) %this displays n but then updates it with the next iteration, I want to insert the value of n into a vector so I can see recall them later.
n=n+1;
else;
n=n+1;
end;
end;
5 件のコメント
Stephen23
2021 年 3 月 6 日
Start here to learn the answer to your question and also fix several other bugs and features of your code:
Matt Baron
2021 年 3 月 6 日
"which part of the tutorial has loop and vector information?"
But this might be more useful than those introductory pages:
Note that MATLAB usually works best when working with vectors/matrices/arrays. So rather than solving that task using a loop, the standard approach would be to generate a vector and use logical indexing to select the values that meet that condition:
"This is the first time I am using code and the amount of information is overwhelming."
I know that feeling! Read the documentation, experiment, read more documentation, don't worry about making mistakes :)
Matt Baron
2021 年 3 月 6 日
Matt Baron
2021 年 3 月 27 日
採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Function Creation についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!