Load data and merge them together

5 Ansichten (letzte 30 Tage)
ZHAOKUO FU
ZHAOKUO FU am 13 Aug. 2020
Bearbeitet: per isakson am 13 Aug. 2020
Dear all,
I am new to matlab and have some problems merging data from mat files in a folder.
All the files are in the same folders named data_n.mat ( data_1.mat, data_5.mat.....). However, some numbers may be missing (data_3.mat does not exist) and there are files withs other formats in this folder.
All of the data files have the same number of columns but different number of rows. What I want to do is to read the data in the first column of each file and merge them vertically. (3*12,4*12 and 5*12, and the new file will be 12*1)
My code is like:
files=dir('\\path\data_*')
data=[];
for n=1:length(files)
data = [data,load(files(n).name)]
end
However, the number of rows of the new files was simply the number of files loaded. (If I load 5 files, there will only be 5 rows)

Antworten (1)

per isakson
per isakson am 13 Aug. 2020
Bearbeitet: per isakson am 13 Aug. 2020
Replacing
data = [data,load(files(n).name)]
with
data = [ data ; load(files(n).name) ];
might help, i.e add rows to data not columns.
"and there are files withs other formats in this folder" Hopefully, there names don't match 'data_*'

Kategorien

Mehr zu File Operations finden Sie in Help Center und File Exchange

Produkte


Version

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by