how to display output in matlab as table enclosed below
Show older comments
i have data as follows as
2 1 -0.307799 0.00
3 0.544459 0.0153522 0.01
4 0.566101 0.00070708 0.02
5 0.567143 -1.40255e-08 0.03
6 0.567143 1.50013e-12 0.04
7 0.567143 0 0.05
how to display output in matlab as table with the first row (enclosed below)
count x f(x) initial
2 1 -0.307799 0.00
3 0.544459 0.0153522 0.01
4 0.566101 0.00070708 0.02
5 0.567143 -1.40255e-08 0.03
6 0.567143 1.50013e-12 0.04
7 0.567143 0 0.05
1 Comment
Shreen El-Sapa
on 29 Jul 2021
How can I get data like this in matlab and put it in table?
I calculated function and I want to put it in tables for various parameters.
Thanks
Answers (2)
Star Strider
on 2 Sep 2016
You can do that using a regular table but you cannot use ‘f(x)’ as a variable name because it is not a valid MATLAB variable name. I have changed it to ‘fx’ here:
Data = [ 2 1 -0.307799 0.00
3 0.544459 0.0153522 0.01
4 0.566101 0.00070708 0.02
5 0.567143 -1.40255e-08 0.03
6 0.567143 1.50013e-12 0.04
7 0.567143 0 0.05];
VarNames = {'count', 'x', 'fx', 'initial'};
T = table(Data(:,1),Data(:,2),Data(:,3),Data(:,4), 'VariableNames',VarNames)
4 Comments
work wolf
on 3 Sep 2016
Star Strider
on 3 Sep 2016
To do it without the table functions, you would have to use a couple of fprintf statements to print it to the Command Window:
Data = [ 2 1 -0.307799 0.00
3 0.544459 0.0153522 0.01
4 0.566101 0.00070708 0.02
5 0.567143 -1.40255e-08 0.03
6 0.567143 1.50013e-12 0.04
7 0.567143 0 0.05];
VarNames = {'count', 'x', 'f(x)', 'initial'};
fprintf(1, ' %s\t\t%s\t\t\t%s\t\t%s\n', VarNames{:})
fprintf(1, '\t%d\t%06f\t%12.5E\t%.2f\n', Data')
count x f(x) initial
2 1.000000 -3.07799E-01 0.00
3 0.544459 1.53522E-02 0.01
4 0.566101 7.07080E-04 0.02
5 0.567143 -1.40255E-08 0.03
6 0.567143 1.50013E-12 0.04
7 0.567143 0.00000E+00 0.05
Note: The output looks correct in the Command Window. The ‘tab’ distances are different in the Answers windows.
work wolf
on 4 Sep 2016
Star Strider
on 4 Sep 2016
My pleasure.
You can only do that with a table object, and you can only do that with R2013b or later.
Another option is:
DataCell = {VarNames, Data};
That puts all the variables in a cell array, but does not actually create a table. That’s as good as it gets without the table funciton.
Azzi Abdelmalek
on 1 Sep 2016
h={'count' 'x' 'f(x)' 'initial'}
data=[2 1 -0.307799 0.00
3 0.544459 0.0153522 0.01
4 0.566101 0.00070708 0.02
5 0.567143 -1.40255e-08 0.03
6 0.567143 1.50013e-12 0.04
7 0.567143 0 0.05]
f=figure;
t=uitable(f,'data',data,'columnname',h)
Categories
Find more on Tables in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!