The easiest way is probably to put everything into a cell array and then write it to a .xls file using writecell. The question then becomes about the best way to create the cell array. If you have a relatively small number of variables that's always the same and has the same size, you can just do it manually.
If you want to automate, here's one way to do it:
a = [1;3;3;4];
b = [1;1;2;4;4;4];
e = 'ADDC';
save variables
data = load('variables');
f = fieldnames(data);
nf = numel(f);
sz = zeros(nf,1);
for j = 1:nf
dataj = data.(f{j});
if ischar(dataj)
dataj = convertCharsToStrings(dataj);
data.(f{j}) = dataj;
end
sz(j) = numel(dataj);
end
mxsz = max(sz);
c = cell(mxsz+1,nf);
c(1,:) = f';
for j = 1:nf
dataj = data.(f{j})(:);
c(2:sz(j)+1,j) = num2cell(dataj);
end
The cell array c is:
7×3 cell array
{'a' } {'b'} {'e' }
{[ 1]} {[1]} {["ADDC" ]}
{[ 3]} {[1]} {0×0 double}
{[ 3]} {[2]} {0×0 double}
{[ 4]} {[4]} {0×0 double}
{0×0 double} {[4]} {0×0 double}
{0×0 double} {[4]} {0×0 double}
Note that I'm unclear on what you wanted for that last column. In your post, you put three rows of "ADDC", and then nothing afterward. I'm guessing that's not what you want. If you only want one appearance of "ADDC", then the above is how you do it. If instead you wanted each character in the character array in a different row, take out the "convert char arrays to string" block, in which case c would be:
7×3 cell array
{'a' } {'b'} {'e' }
{[ 1]} {[1]} {'A' }
{[ 3]} {[1]} {'D' }
{[ 3]} {[2]} {'D' }
{[ 4]} {[4]} {'C' }
{0×0 double} {[4]} {0×0 double}
{0×0 double} {[4]} {0×0 double}
In either case, you can write this to an Excel file by
writecell(c,'variables.xls')
NB: DON'T USE a .xlsx EXTENSION HERE. For some reason, empty values don't get written properly in the .xlsx format and you'll get some strange looking output. Use .xls instead, and if you need to convert to .xlsx, do that manually from inside Excel ("Save as").