Chossing random data from xls files
5 次查看(过去 30 天)
显示 更早的评论
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 个评论
Salaheddin Hosseinzadeh
2014-8-12
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!
采纳的回答
Geoff Hayes
2014-8-12
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 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Spreadsheets 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!