Write Data to .txt or .csv file?

I'm trying to write data that I have in a matrix to a .txt or .csv file. I have data in a 250x2 matrix, and would simply like to be able to write this out to a file of my choice, say 'data.txt' or something like that. Is there an easy way to do this?

 채택된 답변

Oleg Komarov
Oleg Komarov 2011년 8월 4일

0 개 추천

  • dlmwrite: write matrix to ASCII-delimited file
  • csvwrite: write comma-separated value file

댓글 수: 4

Clement Wong
Clement Wong 2011년 8월 4일
Thanks. How do I pick where the default director that it writes to is? Right now, it writes to my MATLAB install folder, but I'd rather have it write to mydocuments, without having to type C:\User\Me\Documents\filename.txt every time. Any easy fix?
Fangjun Jiang
Fangjun Jiang 2011년 8월 4일
You probably can change your MATLAB current folder to that directory, use cd or simply use the "Current Directory" bar above the Command Window.
Oleg Komarov
Oleg Komarov 2011년 8월 4일
compose the destination folder dynamically:
root = 'C:\User\Me\Documents\';
fname = 'filename.txt';
dlmwrite([root fname]...)
Image Analyst
Image Analyst 2011년 8월 4일
Or use fullfile
fullFileName = fullfile(root, fname);
fullfile takes care of creating the correct filename regardless of whether root has a trailing slash or not.
or sprintf
fullFileName = sprintf('%s/%s', root, fname);

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

추가 답변 (0개)

카테고리

Community Treasure Hunt

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

Start Hunting!

Translated by