Effacer les filtres
Effacer les filtres

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

4 vues (au cours des 30 derniers jours)
John Madura
John Madura le 4 Août 2022
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.

Réponse acceptée

John Madura
John Madura le 8 Août 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);

Plus de réponses (1)

Chunru
Chunru le 5 Août 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

Catégories

En savoir plus sur Standard File Formats dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by