Combine mat files into one, then combine all variables into one

5 Ansichten (letzte 30 Tage)
Hello. I have multiple MAT files all containing the same variables with the same name but different lengths. What I'd like to do is combine all the mat files so that my variables will have the data from all the mat files.
So if I have from mat file one
variable 1=[ 1, 2, 3]
variable 2=[1, 2, 3]
and from mat file 2
variable 1= [4, 5, 6, 7]
variable 2 = [4, 5, 6, 7]
They will combine so that I have mat file 3
variable 1 = [1, 2, 3, 4, 5, 6, 7]
variable 2 = [1, 2, 3, 4, 5, 6, 7]
below is an image showing the mat files and some of the variables.

Akzeptierte Antwort

John Madura
John Madura am 8 Aug. 2022
I actually ended up using hte following script which worked for me:
data1 = load("2022_07_28_12_37_19_2022_08_01_17_36_27.mat");
data2 = load("2022_07_28_12_37_19_2022_08_01_17_38_41.mat");
Time = vertcat(data1.variable1, data2.variable1);

Weitere Antworten (1)

Chunru
Chunru am 5 Aug. 2022
filename = ["abc001.mat" "def002.mat"]; % list of the files in order
variable1all = [];
variable2all = [];
for i=1:length(filename)
load(filename(i));
variable1all = [variable1all variable1];
variable2all = [variable2all variable2];
end

Kategorien

Mehr zu Standard File Formats finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by