how to extract rows on certain string and save it in separate files automatically
Show older comments
I have a tall table with information on few hundred (lets say 200) stocks ( which are identified by a string variable, example 'MKO68-N' and their number of shares at each date available. I would like to extract for each stock all the rows from the tall table and then save those into mat file for each stock. So that I get 200 separate files, each file being with information for one stock only. Anyone knows how to do so?
Answers (1)
KL
on 27 Jul 2017
varNames = {'stockNo','param','shares'};
vals = [1,45,10;2,656,20;3,87,30];
T = array2table(vals, 'VariableNames',varNames)
for i=1:length(T.stockNo)
stockData = T(T.stockNo==i,:);
save(['stockData_' num2str(i) '.mat'],'stockData');
end
Categories
Find more on Tables in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!