How do I select a random block of my data using MATLAB?

1 回表示 (過去 30 日間)
MathWorks Support Team
MathWorks Support Team 2018 年 4 月 10 日
編集済み: MathWorks Support Team 2025 年 11 月 10 日
I would like to randomly select a subset of the rows in my data. 
I have a block of data with 284 rows and five columns. I wanted to able to able to create random block of data of length 264. I am not sure what function is best to do this with.

採用された回答

MathWorks Support Team
MathWorks Support Team 2025 年 11 月 10 日
編集済み: MathWorks Support Team 2025 年 11 月 10 日
You can accomplish this using the "randperm" function. For example, to get 264 numbers between 1 and 284, you could use the following code:
>> idx = randperm(284, 264);
If the variable "M" is storing your data, you can then get the rows specified in "idx" with the following code:
>> M_subset = M(idx, :);
For more information on "randperm", please refer to the following documentation link:

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

タグ

製品


リリース

R2013b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by