www.gusucode.com > matlab 案例源码 matlab代码程序 > matlab/ExportTableToTextFileExample.m
%% Export Table to Text File % This example shows how to export a table to a text file, using the % |writetable| function. %% % Create a sample table, |T|, for exporting. % Copyright 2015 The MathWorks, Inc. Name = {'M4';'M5';'M6';'M8';'M10'}; Pitch = [0.7;0.8;1;1.25;1.5]; Shape = {'Pan';'Round';'Button';'Pan';'Round'}; Price = [10.0;13.59;10.50;12.00;16.69]; Stock = [376;502;465;1091;562]; T = table(Pitch,Shape,Price,Stock,'RowNames',Name) %% % The table has both column headings and row names. % % Export the table, |T|, to a text file named |tabledata.txt|. writetable(T,'tabledata.txt') %% % View the file. type tabledata.txt %% % By default, |writetable| writes comma-separated data, includes table variable names as column headings, % and does not write row names. % % Export table |T| to a tab-delimited text file named |tabledata2.txt| and write the row names in the first column of the % output. Use the |Delimiter| name-value pair argument to specify a tab % delimiter, and the |WriteRowNames| name-value pair argument to include % row names. writetable(T,'tabledata2.txt','Delimiter','\t','WriteRowNames',true) %% % View the file. type tabledata2.txt