How can i load a multiple 1D matlab file and store in single mat file?
4 views (last 30 days)
Show older comments
SINAM AJITKUMAR SINGH
on 17 Dec 2018
Commented: Walter Roberson
on 17 Dec 2018
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)
1 Comment
Accepted Answer
Walter Roberson
on 17 Dec 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
0 Comments
More Answers (1)
Mark Sherstan
on 17 Dec 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
0 Comments
See Also
Categories
Find more on Workspace Variables and MAT Files in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!