필터 지우기
필터 지우기

Want to convert .MAT to .TXT

조회 수: 3 (최근 30일)
Sara
Sara 2017년 1월 20일
Hello, I have multiple .MAT structures with multiple variable names and long vectors (3000+ of data) that I would like to process such that the data is put into a .TXT file with the variable names as the column header. EX: (i.e. X=[1.90,2.3] , Y=[2.5467,10.87], Z=[3.134,100.98]. So X, Y, Z are the column headers and the data fall underneath each respective column with the DECIMAL places properly aligned on top of each other.
Question:
I there a script that can do what I need?
Please help
Thank you
Sara

답변 (2개)

Adam
Adam 2017년 1월 20일
doc fprintf
should be able to do what you want, but you'll have to put together the format specification yourself and work out how to get decimal places lined up. This isn't usually something that is important in a text file for raw data.

Jorge Mario Guerra González
Jorge Mario Guerra González 2017년 1월 20일
편집: Jorge Mario Guerra González 2017년 1월 20일
Here is quick way to do that. Using fprint as @Adam says. (This writes with 5 decimal places)
X=[1.90; 2.3]; Y=[2.5467;10.87]; Z=[3.134;100.98];
fid = fopen('example.txt','wt');
fprintf(fid, '%s\t %s\t %s\n', 'X','Y','Z');
fprintf(fid,'%0.5f\t %0.5f\t %0.5f\n',[X Y Z]);
fclose(fid);
You can import it with the headers to excel or whatever.

카테고리

Help CenterFile Exchange에서 Data Type Conversion에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by