read data from variables with names matching patterns

조회 수: 2 (최근 30일)
Roy Goodman
Roy Goodman 2014년 6월 20일
답변: Jos (10584) 2014년 6월 20일
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.

답변 (1개)

Jos (10584)
Jos (10584) 2014년 6월 20일
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') ;

카테고리

Help CenterFile Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by