Can I Load/Combine Vectors Data

조회 수: 3 (최근 30일)
JEONGSOO BAE
JEONGSOO BAE 2017년 8월 3일
답변: Sara Xie 2017년 8월 3일
I have Multiple .mat Files, contains same set of Vector Array names.
For example, I have file1.mat, and file2.mat but both contains a bunch of arrays with same names, like file1.mat has array1 and file2.mat has array1 as well. However, file1.mat array1 has different data than another array1.
For example, file1.mat 's array1 data is
  • 0.01 3
  • 0.04 5
  • 0.05 6
so the first column has time data, and 2nd column has its own corresponding data following the first column data.
but file2.mat array1 has
  • 0.02 19
  • 0.03 22
  • 0.05 25
Is there any way to load/combine those 2 and make
  • 0.01 3
  • 0.04 5
  • 0.05 6
  • 0.07 19
  • 0.08 22
  • 0.10 25
As you observe, the 2nd file's time column is added on the first file but the data kept same.

채택된 답변

ES
ES 2017년 8월 3일
편집: ES 2017년 8월 3일
number_of_mat_files = 2;
for iLoop=1:number_of_mat_files
sMatFileName = ['file', num2str(iLoop), '.mat'];%construct mat file name using the file number
Arr = load(sMatFileName);
if iLoop==1
FinalArr = Arr.a;%a is the name of the variable in the mat file
else
MaxTime = FinalArr(end,1);
Arr = load(sMatFileName);
Arr.a(:,1) = Arr.a(:,1)+MaxTime;
FinalArr = [FinalArr ;Arr.a];
end
end

추가 답변 (1개)

Sara Xie
Sara Xie 2017년 8월 3일
Hi,assume you are loading file1 with array1 and file2 with array1, try save the following function as combineTwoArray.m and run combineTwoArray('file1.mat','file2.mat') to get the combined array.
function array = combineTwoArray(file_1,file_2)
file1 = load(file_1);
file2 = load(file_2);
array_file2 = [(file2.array1(:,1)+file1.array1(length(file1.array1),1)),file2.array1(:,2)];
array = [file1.array1;array_file2];
end

카테고리

Help CenterFile Exchange에서 Structures에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by