How can i load a multiple 1D matlab file and store in single mat file?
3 ビュー (過去 30 日間)
古いコメントを表示
SINAM AJITKUMAR SINGH
2018 年 12 月 17 日
コメント済み: Walter Roberson
2018 年 12 月 17 日
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 件のコメント
採用された回答
Walter Roberson
2018 年 12 月 17 日
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 件のコメント
その他の回答 (1 件)
Mark Sherstan
2018 年 12 月 17 日
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 件のコメント
参考
カテゴリ
Help Center および File Exchange で Workspace Variables and MAT Files についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!