how do I concatenate mat files matlab

2 visualizzazioni (ultimi 30 giorni)
Muhammad Usman
Muhammad Usman il 20 Mar 2015
Commentato: Voss il 21 Dic 2023
I have hundreds of MAT files and i want to concatenate all these files to a single file,each MAT file has dimension of 69x128,here is the technique that I follwed before for fewer files but this is not comfortable for me please provide some comformtable and simpler way to dothe same job
a1=load(sprintf('datafile_%02d',1));
a2=load(sprintf('datafile_%02d',2));
P1 = a.dataselection(:,5:132);
P2 = a2.dataselection(:,5:132);
PO = [P1;P2];
save('PO')
load('PO')

Risposta accettata

Voss
Voss il 20 Dic 2023
Modificato: Voss il 21 Dic 2023
N = 200; % number of files (assumed to be named datafile_01.mat, _02.mat, ..., _10.mat, ..., _99.mat, _100.mat, ..., as you have specified with '%02d')
C = cell(1,N);
for ii = 1:N
A = load(sprintf('datafile_%02d.mat',ii));
C{ii} = A.dataselection(:,5:132);
end
PO = vertcat(C{:});
save('PO.mat','PO')
  4 Commenti
Stephen23
Stephen23 il 21 Dic 2023
Accepted, as it seems to answer the question.
Voss
Voss il 21 Dic 2023
I appreciate it!

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Startup and Shutdown in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by