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

3 ビュー (過去 30 日間)
SINAM AJITKUMAR SINGH
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
Walter Roberson 2018 年 12 月 17 日
Please do not close questions that have an answer.

サインインしてコメントする。

採用された回答

Walter Roberson
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

その他の回答 (1 件)

Mark Sherstan
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

カテゴリ

Help Center および File ExchangeWorkspace Variables and MAT Files についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by