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

5 visualizaciones (últimos 30 días)
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.

Respuesta aceptada

John Madura
John Madura el 8 de Ag. de 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);

Más respuestas (1)

Chunru
Chunru el 5 de Ag. de 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

Categorías

Más información sobre Standard File Formats en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by