How to merge the three mat files?

3 ビュー (過去 30 日間)
Sadiq Akbar
Sadiq Akbar 2024 年 3 月 5 日
コメント済み: Mathieu NOE 2024 年 3 月 5 日
I have three mat files. I wan a new mat file to which I want to copy the data of all these 3 mat files except the variables for which first I want to merge their data and then store that merged data in that new mat file. The variables for which I want merging their data are:
1- All "one1" variables in a single variable
2- All "two" variables in a single variable
3- All "time" variable in a single variable
  3 件のコメント
Walter Roberson
Walter Roberson 2024 年 3 月 5 日
How do you want to handle (for example) Noise ? You want to copy the data of the three mat files, so you want to copy Noise. Should we assume that all the values are the same between the mat files except for one1 two and time ? Should we produce (for example) Noise1 Noise2 Nois3 ?
whos -file a1
Name Size Bytes Class Attributes Noise 1x1 8 double NoiseRange 1x31 248 double Runs 1x1 8 double bestFitness 1x1 8 double bestFitness_temp 1x1 8 double bestVector 1x3 24 double bestVector_temp 1x3 24 double dim 1x1 8 double i 1x1 8 double ix 1x3 24 double ix1 1x3 24 double j 1x1 8 double lb 1x3 24 double one 31x1 248 double one1 31x1 248 double time 1x1 8 double two 31x1 3968 cell u 1x3 24 double ub 1x3 24 double
whos -file a2
Name Size Bytes Class Attributes Noise 1x1 8 double NoiseRange 1x31 248 double Runs 1x1 8 double bestFitness 1x1 8 double bestFitness_temp 1x1 8 double bestVector 1x3 24 double bestVector_temp 1x3 24 double dim 1x1 8 double i 1x1 8 double ix 1x3 24 double ix1 1x3 24 double j 1x1 8 double lb 1x3 24 double one 31x1 248 double one1 31x1 248 double time 1x1 8 double two 31x1 3968 cell u 1x3 24 double ub 1x3 24 double
whos -file a3
Name Size Bytes Class Attributes Noise 1x1 8 double NoiseRange 1x31 248 double Runs 1x1 8 double bestFitness 1x1 8 double bestFitness_temp 1x1 8 double bestVector 1x3 24 double bestVector_temp 1x3 24 double dim 1x1 8 double i 1x1 8 double ix 1x3 24 double ix1 1x3 24 double j 1x1 8 double lb 1x3 24 double one 31x1 248 double one1 31x1 248 double time 1x1 8 double two 31x1 3968 cell u 1x3 24 double ub 1x3 24 double
Sadiq Akbar
Sadiq Akbar 2024 年 3 月 5 日
Thanks a lot for your kind responses. Yes, I want to copy the data of all the variables as it is but I want to concatenate the data of the mentioned variables using the same variables names. However, in addition to that if you can do interpolation or subsampling of the mentioned variables and by storing the interploated or subsampled data in new variables, it will be much better.

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

採用された回答

Mathieu NOE
Mathieu NOE 2024 年 3 月 5 日
hello
a quick and dirty solution, you may have to find a way to generalize to more variables in that may be the case in the future
fileDir = pwd; % current directory (or specify which one is the working directory)
S = dir(fullfile(fileDir,'a*.mat')); % get list of data files in directory
%% recommended
% S = natsortfiles(S); % sort file names into natural order , see :
% %(https://fr.mathworks.com/matlabcentral/fileexchange/47434-natural-order-filename-sort)
out_one = []; % one
out_two = []; % two
out_time = []; % time
for k = 1:length(S)
filename = S(k).name % shows filenames are correctly sorted (see command window)
load( fullfile(fileDir, filename)); %
out_one = [out_one; one]; % vertical concatenation
out_two = [out_two; cell2mat(two)]; % vertical concatenation
out_time = [out_time; time(:)]; % vertical concatenation
end
  2 件のコメント
Sadiq Akbar
Sadiq Akbar 2024 年 3 月 5 日
Thanks a lot for your guiadance.
Mathieu NOE
Mathieu NOE 2024 年 3 月 5 日
my pleasure !!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by