MATLAB Answers

output table with different variable lengths

19 views (last 30 days)
Jocelyn
Jocelyn on 9 Jan 2021
Commented: VBBV on 10 Jan 2021
Hello,
I would like to output the following variables into one table within excel.
Variables:
DivPar_x
DivPar_y
phata_values
When I run my code I can only get it to work when I do not include the 'phata_values' when creating the table (as written in code below).
I think it will not work when I add the 'phata_values' into the table because it shows that it has 334 columns of data; where as the DivPar_x and DivPar_y both have 336 columns of data. Is this where the error could be coming from? If so, how do I make it so the three variables can be the same size of array lengths [1 x 336]
Secondly,
Is there a way to re-configure the table so it is not printing: 1 row and 336 columns but 1 column and 336 rows?
Thank you for your assistance!
% to get phata need to take derivative
phata2_Y_diverging = diff(Y_2);
phata2_X_diverging = diff(x_b);
phata3_Y_parabala = diff(Y_3);
phata3_X_parabala = diff(X_3);
% create table to output to excel
DivPar_x =[x_b, X_3]; % [1 x 336 double]
DivPar_y = [Y_2, Y_3]; % [1 x 336 double]
phata_values = [phataY./phataX]; % [1 x 334]
T = table([DivPar_x; DivPar_y])
%% T = table([DivPar_x; DivPar_y; phata_values]) --> produces an error / will not output to excel
writetable(T, 'test2.xlsx')

  0 Comments

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 9 Jan 2021
Use gradient() instead of your current diff() based system. The output will be the same size as the input.

  0 Comments

Sign in to comment.

More Answers (1)

VBBV
VBBV on 10 Jan 2021
Edited: VBBV on 10 Jan 2021
%if true
% to get phata need to take derivative
phata2_Y_diverging = diff(Y_2);
phata2_X_diverging = diff(x_b);
phata3_Y_parabala = diff(Y_3);
phata3_X_parabala = diff(X_3);
% create table to output to excel
DivPar_x =[x_b, X_3]; % [1 x 336 double]
DivPar_y = [Y_2, Y_3]; % [1 x 336 double]
phata_values = [phataY./phataX]; % [1 x 334]
phata_values = [phata_values 0 0]
T = table(DivPar_x.', DivPar_y.', phata_values.')
writetable(T, 'test2.xlsx')
Try the above

  1 Comment

VBBV
VBBV on 10 Jan 2021
%if true
T = table(DivPar_x.',DivPar_y.',phata_values.','VariableNames',{'parx','pary','phata'})
You can set variable names

Sign in to comment.

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by