Save file .txt in desktop

Hello, I want to save a file with the format .txt in my desktop, not in matlab/Work. This is my program:
clear all;
Name_file=input('Tell me the name of the file(example.dat): ','s');
X=[ 0 0.5 0.75 1];
Y=[ 0 1 2 3];
A=[X' Y'];
[n,m]=size(A);
fid=fopen(Name_file,'w');
for i=1:n
for j=1:m
fprintf(fid,'%8.4f\t',A(i,j));
end
fprintf(fid,'\n');
end
fclose(fid);

 採用された回答

Fangjun Jiang
Fangjun Jiang 2011 年 8 月 15 日

0 投票

[File,Folder]=uiputfile;
dlmwrite(fullfile(Folder,File),A,'delimiter',' ','newline','pc');

その他の回答 (1 件)

Xenxo
Xenxo 2011 年 8 月 16 日

0 投票

Thank you Fangjun Jiang, my program will be: clear all; Name_file=input('Tell me the name of the file(example.dat): ','s'); X=[ 0 0.5 0.75 1]; Y=[ 0 1 2 3]; A=[X' Y']; [n,m]=size(A); fid=fopen(Name_file,'w'); for i=1:n for j=1:m fprintf(fid,'%8.4f\t',A(i,j)); end fprintf(fid,'\n'); end fclose(fid); [File,Folder]=uiputfile; dlmwrite(fullfile(Folder,File),A,'delimiter',' ','newline','pc');
I have a new problem, the file is save in desktop and at the same time in matlab/work and I don´t want it. How can I do for not saving in matlab/work?
Thank you

1 件のコメント

Fangjun Jiang
Fangjun Jiang 2011 年 8 月 16 日
All you need is the lines that assign value to A and the last two lines to select a file and then write to the file. You don't need the for-loop anymore. That's probably why two files are created.

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeDesktop についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by