How can I use "datasample" to get multiple samples without a loop?
13 ビュー (過去 30 日間)
古いコメントを表示
MathWorks Support Team
2020 年 6 月 2 日
編集済み: MathWorks Support Team
2025 年 2 月 4 日
How can I create "n" samples of size "k" using "datasample" without needing a "for" loop?
To access detailed documentation on the "datasample" function, execute the following command in MATLAB R2020b:
>> web(fullfile(docroot, 'stats/datasample.html'))
For example, if I want to sample from a 500 element vector in samples of 20, but do that 30 times, I've got to create a loop from i=1:30 with "datasample" inside that loop.
採用された回答
MathWorks Support Team
2025 年 1 月 24 日
編集済み: MathWorks Support Team
2025 年 2 月 4 日
To create multiple samples of a certain size, you can use the "reshape" command after generating all the values needed. For example:
>> x = rand([500,1]); >> sampleSize = 20; >> numSamples = 30; >> y = datasample(x, sampleSize * numSamples); >> z = reshape(y, [numSamples, sampleSize]);
To access the documentation for "reshape," execute the following command in MATLAB R2020b:
>> web(fullfile(docroot, 'matlab/ref/reshape.html'))
Please follow the link below to search for the required information regarding the current release:
0 件のコメント
その他の回答 (0 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!