how to extract rows on certain string and save it in separate files automatically

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?

Réponses (1)

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

Catégories

Question posée :

le 27 Juil 2017

Réponse apportée :

KL
le 27 Juil 2017

Community Treasure Hunt

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

Start Hunting!

Translated by