MATLAB: Problem displaying data on spreadsheet

spreadsheettable

i have a few variables (arrays) that i need to dispaly in table form then write that table to spreadsheet file here's the part where declare the variables(im using app designer):
a1=a1*0.001;
bx1=app.bx.Value;
db1=app.db.Value;
j=(bx1-b1)/db1 + 1;
j=fix(j);
i=1;
bb=1:j;
ph=1:j;
ta=1:j;
zl=1:j;
zy=1:j;
this is the part of the code i used to print those variables into spreadsheet file after they enter a while loop which writes numbers to these variables:
TT=table(b1,ph,ta,zl,zy);
my_directory='F:\project';
test_sheet=fullfile( my_directory, 'testsheet.xlsx');
writetable(TT, test_sheet, 'filetype','spreadsheet','sheet',1);
now the problem is that when the spreadsheet file comes out all the data in those variables are in the same row (also the first variable b1 only shows the last number in the array) as shown in the included attachment.
i've tried a lot of things but nothing seems to work either everything stays the same or it gets worse. any help is very appreciated.
Capture.PNG

Best Answer

When you create a table, if you want the elements of the inputs to become rows of the table, then you need these inputs to be column vectors
So,
j = 5;
bb=1:j;
ph=1:j;
ta=1:j;
zl=1:j;
zy=1:j;
TT = table(bb,ph,ta,zl,zy);
creates a table with one row (all the inputs have only one row), where each variable is a 1x5 vector. Not very useful
j = 5;
bb = (1:j)'; %variable is now a column vector




ph = (1:j)'; %variable is now a column vector
ta = (1:j)'; %variable is now a column vector
zl = (1:j)'; %variable is now a column vector
zy = (1:j)'; %variable is now a column vector
TT = table(bb,ph,ta,zl,zy);
creates a table with 5 rows, each variable is a 5x1 by one vector. When written to excel, you'll get the result you want.