read data from variables with names matching patterns

2 vues (au cours des 30 derniers jours)
Roy Goodman
Roy Goodman le 20 Juin 2014
A student of mine saved a .mat file containing variables named x1, x2, ..., x50, y1, y2, etc. How can I write program that will open the .mat file, and loop through each of these pairs of data. Somehow it involves "who" but I'm not seeing how to make it work.
  2 commentaires
Roy Goodman
Roy Goodman le 20 Juin 2014
answer to my own question: use the "eval" command.

Connectez-vous pour commenter.

Réponses (1)

Jos (10584)
Jos (10584) le 20 Juin 2014
X = load('StudentsMatfile.mat') ;
LABELS = fieldnames(X) ;
N = numel(LABELS)
DATA = cell(N,1)
for k=1:N
DATA{k} = X.(LABELS{k}) ;
end
save ('SupervisorMatfile.mat', 'DATA','LABELS') ;

Catégories

En savoir plus sur Get Started with MATLAB dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by