0
votes

I have a structure face_data that contains two fields. The first is a 360x1 cell array face_test where each cell contains a 88x72 image of a face. The second field is the cell array label_test, which contains a label for each face.

What I'd like to do is convert each face image in each of the 360 cells into a column vector - that is, I want to convert face_test into a 6336 x 360 matrix where each column represents an unrolled face image. I'm new to matlab though and don't know how to do this without a bunch of looping that I guess is unnecessary. Can someone give me a simple solution to this problem?

2

2 Answers

1
votes

A simple loop should do this fast enough since you know the sizes beforehand

A = % .. this is your cell array of data cell(360,1)
B = zeros(numel(A{1}), length(A)); % or zeros(6336, 360)
for i = 1 : length(A)
   B(:, i) = reshape(A{i}, [], 1);
end
0
votes

Okay, this is where Matlab's functions can help. The code is

face_data.face_test = reshape(cell2mat(face_data.face_test), [], numel(face_data.face_test));

You can easily check if this is what you want by testing this code:

s = struct('a', cell(1), 'b', cell(1));
s.a = {reshape(1:9, 3, []), 9+reshape(1:9, 3, []), 18+reshape(1:9, 3, [])}
reshape(cell2mat(s.a), [], numel(s.a))