I have two .mat files x1.mat and x2.mat. The first column of both the .mat files contains folder/file name. The second column contains the bounding box values that is different for both the .mat files. The format is like this:(image name, bounding box values). I need to create a new .mat file by appending both the .mat files in such a way that the resultant .mat file contains three columns such that the second column contains the bounding box information of x1.mat and the third column contains the bounding box information of x2.mat. The missing entries in both these columns should contain the values [0,0,0,0].

Antworten (1)

Prakhar Jain
Prakhar Jain am 25 Sep. 2018

0 Stimmen

Let mat files be X1.mat and X2.mat. Load them into workspace.
load X1.mat;
load X2.mat;
First_col = unique([X1(:,1) ; X2(:,1)]); %This will give the unique file/folder names
rows = size(First_col,1);
AppendMat = cell(rows,3);
for i=1:rows
AppendMat{i,1} = First_col(i);
first = find(First_col(i) == X1(:,1));
if(isempty(first))
AppendMat{i,2} = [0 0 0 0]
else
AppendMat{i,2} = X1(i,2);
end
second = find(First_col(i) == X2(:,1));
if(isempty(second))
AppendMat{i,3} = [0 0 0 0]
else
AppendMat{i,3} = X2(i,2);
end
end
% AppendMat cell contains the required combined output

4 Kommentare

It doesn't work. When trying to execute the for loop, the following error shows up:
You cannot subscript a table using linear indexing (one subscript) or multidimensional indexing (three or more subscripts). Use a
row subscript and a variable subscript.
Prakhar Jain
Prakhar Jain am 26 Sep. 2018
Can you share your .mat files
Sivaramakrishnan Rajaraman
Sivaramakrishnan Rajaraman am 26 Sep. 2018
PFA the MAT files.
Sivaramakrishnan Rajaraman
Bearbeitet: Sivaramakrishnan Rajaraman am 2 Okt. 2018
Do you mind answering this question? the requested files have been uploaded. thanks.

Melden Sie sich an, um zu kommentieren.

Community Treasure Hunt

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

Start Hunting!

Translated by