how to write this data in text file?

4 次查看(过去 30 天)
Hi,
how can i store my data in .txt as it is shown in workspace that is in separate column..
where variable name is sets(9:i) now this i is 5 in this case but it could be other wise
for i=1:5
fprintf(fid, '%.2f\n',sets(9,i) );
end
not working..its writing all (9*5) data in a single column...

采纳的回答

Sara
Sara 2014-7-30
Try this:
sets = rand(9,5)
for i = 1:9
fprintf(fid,'%.2f ',sets(i,:) );
fprintf(fid,'\n');
end

更多回答(2 个)

Roger Wohlwend
Roger Wohlwend 2014-7-30
Use the function csvwrite:
csvwrite(filename,Matrix)
Or consider saving the matrix in a mat-file using the command save.

Azzi Abdelmalek
Azzi Abdelmalek 2014-7-30
dlmwrite('your_file.txt',M) % M is your matrix

类别

Help CenterFile Exchange 中查找有关 Workspace Variables and MAT-Files 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by