MATLAB: Write vectors in cell array to excel

cell arraysexcelMATLABsavexlswrite

Hi all,
I'm wondering if there is any easy way to write vectors stored in a cell array (Data = cell(50,2)) to excel. At the moment I'm using a for loop but it seems quite messy. Preferably I would store them in pairs:
Column A = Data{1,1}
Column B = Data{1,2}
Column C = Data{2,1}
Column D = Data{2,2}
etc
Best,
Rick

Best Answer

Is this what you're trying to do?
%Making a sample cell array with variable-length vectors
Data = cell(50, 2);
for j = 1:50
L = randi(10);
Data(j, :) = {rand(1, L) rand(1, L)};
end
%Saving to excel format
MaxLen = max(cellfun('length', Data(:, 1)));
AllData = cell(MaxLen, numel(Data));
for j = 1:size(Data, 1)
L = numel(Data{j, 1});
AllData(1:L, 2*j-1) = num2cell(Data{j, 1});
AllData(1:L, 2*j) = num2cell(Data{j, 2});
end
xlswrite('test.xlsx', AllData)