How can I limit the maxmimum number of files to be loaded from a database?

Suppose I have a database of 200k files (.mat files) but I want to randomly open only 15000 files out of those 200k. Is there a way to do that? Thanks in advance..

 採用された回答

Matt Kindig
Matt Kindig 2012 年 10 月 16 日
編集済み: Matt Kindig 2012 年 10 月 16 日
You could use dir() to get the names of all *.mat files, and then use randperm() to randomly choose 15000 of them. Something like this:
matFiles = dir('*.mat'); %get all mat files
n = randperm(200e3); %generate numbers between 1 and 200k in random order
n = n(1:15e3); %get first 15k numbers
matFiles = matFiles(n); %this will have 15k mat files, randomly chosen.

1 件のコメント

Sim
Sim 2012 年 10 月 16 日
Thank you so much. It works great..!!!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeWorkspace Variables and MAT Files についてさらに検索

タグ

質問済み:

Sim
2012 年 10 月 16 日

Community Treasure Hunt

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

Start Hunting!

Translated by