Dear All, I am trying to export my output data from MATLAB into a text file, I attached a sample of the required FORMAT for the output file, and also the code I wrote to form the table, how can I please make it look like the output file I attached? Thank you
Month = {'January';'January';'January';'January';'January';'January';'January';'January';'January';'January'};
Class = [4;5;6;7;8;9;10;11;12;13];
Total = [100;100;100;100;100;100;100;100;100;100;];
Single = [Values_S_C4';Values_S_C5';Values_S_C6';Values_S_C7';Values_S_C8';Values_S_C9';Values_S_C10';Values_S_C11';...
Values_S_C12';Values_S_C13'];
T = table(Month,Class,Total,Single)
writetable(T,'tabledata.txt');
type tabledata.txt

 채택된 답변

Guillaume
Guillaume 2019년 4월 4일

1 개 추천

Assuming that your Values_S_Cx vectors were column vectors so that Single is a numel(Total) x Ncolumns matrix, then:
writetable(T, 'tabledata.txt', 'WriteVariableNames', false);
If using R2019a, you could store your data in a cell array instead of a table, and then use writecell instead.
C = [Month, num2cell([Class, Total, Single])];
writecell(C, 'tabledata.txt');
Note that you should never create numbered or serially named variables such as your Values_S_Cx. They should have been stored straight away as just one variable.

댓글 수: 6

MAHMOUD ALZIOUD
MAHMOUD ALZIOUD 2019년 4월 4일
This is amazing, Thank you very much
MAHMOUD ALZIOUD
MAHMOUD ALZIOUD 2019년 4월 4일
Just 1 final questiosn, how can I make the zeros in 2 digits, for example 0.00 instead of 0 in the text file
Guillaume
Guillaume 2019년 4월 4일
That's not supported by writetable or writecell. For that you'll have to use the low level functions such as fprintf.
Peter Perkins
Peter Perkins 2019년 4월 4일
Just for the record, storing tabular data like that in a cell array is, usually, not a good idea. Memory-wise, it's very inefficient, and will run into issues even for moderately (by today's standards) large data. Usability-wise, it's going to be very clumsy to work with numeric data, such as total, in the cell array.
But kudos for being very up-to-date with writecell!
MAHMOUD ALZIOUD
MAHMOUD ALZIOUD 2019년 4월 4일
What is your suggestion please?
Peter Perkins
Peter Perkins 2019년 4월 8일
A table, or a timetable, probably containing a mix of numeric and categroical variables.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Data Type Conversion에 대해 자세히 알아보기

질문:

2019년 4월 4일

댓글:

2019년 4월 8일

Community Treasure Hunt

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

Start Hunting!

Translated by