MATLAB: Writing a Script..

MATLABwriting a script

Hi all.. I have a bunch of mat files consisting of 25 types data each inside. I am interested in only 4 of them. They also are in another directory different than matlab. What I want to do is reading only all 4 data from all mat files. How can I write a script for this.. Thnx

Best Answer

  • D = 'absolute or relative path to the folder file where the files are saved';
    S = dir(fullfile(D,'Case*.mat'));
    N = numel(S);
    C = cell(1,N);
    for k = 1:N
    % change 'f1' etc. to the names of the data you want:
    T = load(fullfile(D,S(k).name),'f1','f2','f3','f4');
    S(k).f1 = T.f1;
    S(k).f2 = T.f2;
    S(k).f3 = T.f3;
    S(k).f4 = T.f4;
    It will import the required file data into the structure S: