MATLAB: How to Add Headings to a list of data

array

Here is the code I have.
function[root,ea,iter]=secant(func,delta,xr,es,maxit,varargin)
if nargin<3,error('atleast 3 input arguments required'),end
if nargin<4|isempty(es),es=0.0001;end
if nargin<5|isempty(maxit),maxit=50;end
iter=0;
T=[]
while (1)
xrold=xr;
xr=xr-((delta*xr*func(xr))/(func(xr+(delta*xr))-func(xr)));
iter=iter+1;
if xr~=0, ea=abs((xr-xrold)/xr)*100;end
if ea<=es|iter>=maxit,break,end
funcxr=func(xr);
T=[T;[iter,xr,func(xr),ea]];
end
T
root=xr;
Here is the output.
>> secant(@(x) 6*x^2-13*x-5,10^-6,1.2)
T =
[]
T =
1.0000 9.7428 437.8779 87.6832
2.0000 5.5290 106.5398 76.2143
3.0000 3.5319 23.9303 56.5448
4.0000 2.7174 3.9799 29.9710
5.0000 2.5145 0.2472 8.0718
6.0000 2.5001 0.0012 0.5757
7.0000 2.5000 0.0000 0.0029
ans =
2.5000
I need to have headings on the top of the colmuns and have no clue how to add them. Please help

Best Answer

If you have R2013b or later, use a table. The documentation explains how to specify and add the variable names. Note that if you have R2019b or later, the variable names do not need to be valid MATLAB identifiers.