Chossing random data from xls files
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
Muhammad Usman
il 12 Ago 2014
Risposto: Geoff Hayes
il 12 Ago 2014
I have hundreds of excels files in different folders with data on hundreds of records,I want to record the data to a single (excel) file that choose randomly files from the folder and the rows (randomly too...) Please guide me what is the procedure that I adopt to cater this thing. Thanks
3 Commenti
Salaheddin Hosseinzadeh
il 12 Ago 2014
It's a pure programming problem.
Anyone with a little creativity, knowledge of programming, and of course some hours to think and trial and error should be able to tackle this really!
I don't see a point to ask this!
Risposta accettata
Geoff Hayes
il 12 Ago 2014
Muahmmad - do you know what the minimum number of rows are in each file? If so, then you could create a vector of integers, one for each file, where the sum of all elements in the vector is 100000 (the number of rows that you want to extract). You can initialize the vector to that of all ones
numFiles = 29000;
selRowsPerFile = ones(numFiles,1);
so that at least one row is selected from each file.
There may be some code on the MATLAB File Exchange that can create this vector for you (subject to the constraint of each element in the vector being at least one, and the sum of the elements in the vector being exactly 100000). If not, then you could write a simple while loop with randi to randomly select more rows for each file, until the 100000 rows have been assigned.
Then, once you have your list of files, for each file you can use xlsread to read in the data and then randomly selected a number of rows (again using randi) from that data (using the selRowsPerFile vector to tell you how many rows to read). Once those rows have been selected, then use xlswrite to write the data to file.
0 Commenti
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Spreadsheets in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!