Speadsheet with all the answers from my loop
1 回表示 (過去 30 日間)
古いコメントを表示
I created a for loop that was meant to show me how many times a number showed up in an array like so:
for i=1:n
length(find(yy(1:numel(yy),1)==i))
end
It worked but it did so in a way that gave me eac number's answer one at a time in my command window like so:
ans=
7
ans=
2
and so on.
How do I code it so that I create a speadsheet that tells me the answer from 1 all the way to the last number?
2 件のコメント
Geoff Hayes
2019 年 10 月 14 日
Jordan - what are you trying to write to file? A list of the integers and the number of times they appear in the array?
採用された回答
the cyclist
2019 年 10 月 14 日
編集済み: the cyclist
2019 年 10 月 14 日
output = zeros(n,1);
for i=1:n
output(i) = length(find(yy(1:numel(yy),1)==i));
end
output
That will still write the full list to the screen, but without the intervening "ans" text.
There are then a number of ways to write to file. Perhaps check out this documentation as a starting point.
その他の回答 (0 件)
参考
カテゴリ
Help Center および 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!