MATLAB: Add empty cell inside a cell array considering a single array

arraycell arraysMATLAB

Hi I have a cell array
GGG = {{[1 2 2 1 3 4 9 9 6 1 3 3 2 1 2 4 3 ; 5 10 15 20 25 30 35 40 45 50 55 60 65 70 75 80 85],[ 2 2 3 3 4 9 4 9 6 4 9 3 3 2 2 4 ; 5 10 15 20 25 30 35 40 45 50 55 60 65 70 75 78]},{[ 2 2 3 3 4 9 4 9 6 4 9 3 3 2 2 4 ; 5 10 15 20 25 30 35 40 45 50 55 60 65 70 75 78]}};
given an array
SP= [1 2 3 4 5 6]
I want to add in each cell of GGG a number of empty cell that is equal to the maximum value inside SP minus the actual number of cell in each cell of GGG
CONSIDERING THE FIRST CELL OF GGG, is a 1*2 cell. inside this cell I want to add 6-2=4 empty cell
CONSIDERING THE SECOND CELL OF GGG, is a 1*1 cell, inside this cell I want to add 6-1=5 empty cell
obtaining
GGG = {{[1 2 2 1 3 4 9 9 6 1 3 3 2 1 2 4 3 ; 5 10 15 20 25 30 35 40 45 50 55 60 65 70 75 80 85],[ 2 2 3 3 4 9 4 9 6 4 9 3 3 2 2 4 ; 5 10 15 20 25 30 35 40 45 50 55 60 65 70 75 78],[],[],[],[]},{[ 2 2 3 3 4 9 4 9 6 4 9 3 3 2 2 4 ; 5 10 15 20 25 30 35 40 45 50 55 60 65 70 75 78],[],[],[],[],[]}};
May someone help me with this code?

Best Answer

Surely, by now, with all the questions you've asked, you should be able to manipulate cell arrays yourself.
Anyway:
desiredlenght = max(SP);
result = cellfun(@(c) [c, cell(1, desiredlength - numel(c))], GGG, 'UniformOutput', false)