필터 지우기
필터 지우기

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

조회 수: 4 (최근 30일)
John Madura
John Madura 2022년 8월 4일
답변: John Madura 2022년 8월 8일
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.

채택된 답변

John Madura
John Madura 2022년 8월 8일
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);

추가 답변 (1개)

Chunru
Chunru 2022년 8월 5일
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

카테고리

Help CenterFile Exchange에서 Standard File Formats에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by