concatenate multiple variables from multiple .mat files

1 view (last 30 days)
adi kul
adi kul on 10 Dec 2019
Edited: adi kul on 10 Dec 2019
Hello All,
I need a help in concatenate multiple variables from multiple .mat files stored in multiple folders.
Below is my code, I am not able to get forward with the logic.
clear all
close all
d = uigetdir();
S = dir(fullfile(d,'*'));
N = setdiff({S([S.isdir]).name},{'.','..'});
inputfile=fullfile(d, 'input.xlsx');
input_file=dir(inputfile);
read_inputs=readtable([d '\' input_file.name]);
parameter_list={'Var_1','Var_2','Var_3'};
for ii = 1:numel(N)
T =dir(fullfile(d,N{ii},'*.mat'));
T([T.isdir]) = [];
fprintf('Now Reading Folder %s\n',d,N{ii});
for jj = 1:numel(T)
F = fullfile(d,N{ii},T(jj).name);
fprintf('Now Reading file %s\n',F);
for kk = 1:numel(parameter_list)
Parameter_name=char(parameter_list(kk));
x=load(F);
if isfield(x,Parameter_name)
fprintf('Found paramter=%s\n',Parameter_name);
parameter(:,kk).data = (x.(char(Parameter_name)));
end
Conc_paramter(:,jj).data=vertcat(parameter.data);
end
end
end
What I want is a final .mat file where all the parameters are concatenated with parameter names.

Answers (0)

Community Treasure Hunt

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

Start Hunting!