How can i load a multiple 1D matlab file and store in single mat file?

4 Ansichten (letzte 30 Tage)
I have around 400 1D mat files of different size. For example data1 having a size of 1X65000, data2 having size of 1X 45900 and so on... upto data400 having a size of 1X 36000.
how can i store this mat file as Result.mat having file size (400 X minimum length)

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 17 Dez. 2018
all_data = zeros(400,0);
for K = 1 : 400
thisfile = sprintf('data%d.mat');
filestruct = load(thisfile);
varnames = fieldnames(filestruct);
firstvarname = varnames{1};
this_data = reshape(filestruct.(firstvarname), 1, []);
if K == 1
all_data = data;
Lall = length(data);
else
L = length(this_data);
if L < Lall
Lall = L;
all_data = all_data(:,1:Lall);
end
all_data(K, :) = this_data(1:Lall);
end
end

Weitere Antworten (1)

Mark Sherstan
Mark Sherstan am 17 Dez. 2018
Everything will be in a cell aray but this will do the trick:
for ii = 1:numel(dir('*.mat'))
result{ii} = load(strcat('data',num2str(ii),'.mat'));
end

Kategorien

Mehr zu Workspace Variables and MAT Files finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by