How to save table in workspace as txt/.m file in matlab ?

조회 수: 9 (최근 30일)
Abhishek H P
Abhishek H P 2016년 5월 23일
편집: Kirby Fears 2017년 1월 5일
Hi,
Table is a variable containing 99*1 double values saved in workspace. I need to convert it into txt/.m file

답변 (1개)

Kirby Fears
Kirby Fears 2016년 5월 23일
편집: Kirby Fears 2016년 5월 23일
You can use writetable to write to a text file.
writetable(data,'outputfile.txt');
If you really need this to be a .m file, you can make a new copy as .m and delete the original file.
copyfile('outputfile.txt','outputfile.m');
delete('outputfile.txt');
  댓글 수: 2
Abhishek H P
Abhishek H P 2017년 1월 1일
Thanks for the response however I got error My input: writetable(A,'outputfile.txt') where A is the variable containing doubles 99*1
My output was: Undefined function 'write' for input arguments of type 'double'.
Error in writetable (line 121) write(a,filename,varargin{:})
Kirby Fears
Kirby Fears 2017년 1월 5일
편집: Kirby Fears 2017년 1월 5일
Abhishek,
In that case, what you have is a double array instead of a table (in Matlab parlance).
You can simply use csvwrite. Here's an example.
csvwrite('outputfile.txt',magic(10));
If you want the result to be .m format, just indicate the file name accordingly:
csvwrite('outputfile.m',magic(10));

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

카테고리

Help CenterFile Exchange에서 Environment and Settings에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by