Trying to add borders to a table to save as .txt
14 views (last 30 days)
Show older comments
So i have 3 lists, which I am trying to make into a table. Initially I just used T=table(x,y,z), but this was not aligned and had no borders. So now I am trying to set up the table first with borders, then append the lists to the table. I am getting this error message and I have no idea to solve it, and am struggling to find any other way to make a table with borders.
Thanks in advance
"Error using append (line 38) Wrong number of input arguments for obsolete matrix-based syntax."
if true
function example()
import mlreportgen.dom.*;
table = Table(3);
table.Style = {Border('inset','red','3px'), ...
ColSep('single','green','1px'), ...
RowSep('single','green','1px')};
table.Width = '50%';
x={'a';'b';'c'}
y=[1;2;3]
z=[4;5;6]
%T=table(x,y,z)
%append(T,table)
append({x,y,z},table)
%writetable(T,'mydata.txt')
end
end
0 Comments
Answers (1)
Rajanya
on 23 Dec 2024 at 11:10
I was able to reproduce the error. The error is because of wrong usage of the ‘append’ function which is being done presumably to append the lists in the table ‘table’.
As per the documentation, the correct way to append a row to a table is:
append(table,row);
where ‘row’ is specified as an ‘mlreportgen.ppt.TableRow’ object, which is not the case in the following line and hence the error.
append({x,y,z},table)
The below example shows a way to add a row to a table named 'tab'.
tab = Table();
append(tab,TableRow());
After adding all the rows and styling the table accordingly, you can then iterate and fill in the row entries using ‘TableRow’s append’ functionality which appends content to a table row.
Also, if you are considering using the ‘append’ function of the ‘mlreportgen.dom.Document’ class to write this table, please note that exporting directly to a text file isn't supported. The available output types for report generation include ‘docx’, ‘html’, ‘html-file’, ‘html-multipage’, and ‘pdf’. For extracting the table specifically to ‘txt’, you may want to extract the data entries manually and dump it into a text file and the borders may be represented by horizontal and vertical dashes (‘-’) since ‘.txt’ files do not support any additional formatting functionalities (like bordering) apart from plain text.
To know more about ‘mlreportgen.dom.Document’, ‘mlreportgen.ppt.Table’ and ‘mlreportgen.ppt.TableRow’ classes and their properties and methods, you can visit their respective documentation pages by executing the following commands from MATLAB command window:
doc mlreportgen.dom.Document
doc mlreportgen.ppt.Table
doc mlreportgen.ppt.TableRow
Thanks!
0 Comments
See Also
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!