MATLAB Answers

0

I wanna save text as txt file in my desktop or any location I choose

Asked by Mohammed alfath Ahmed on 15 Sep 2019
Latest activity Answered by Walter Roberson
on 15 Sep 2019
Text='hello' [file, path] =uiputfile('text. Txt')

  1 Comment

You intended more like
Text='hello';
[file, path] =uiputfile([Text '.txt']);
maybe?

Sign in to comment.

Tags

1 Answer

Answer by Walter Roberson
on 15 Sep 2019

Text='hello';
[file, pathdir] = uiputfile('text. Txt');
if isempty(file); return; end %user cancel
fullname = fullfile(pathdir, file);
[fid, msg] = fopen(fullname, 'wt');
if fid < 0
error('Failed to open file "%s" because "%s"', fullname, msg);
end
fprintf(fid, '%s\n', Text);
fclose(fid);

  0 Comments

Sign in to comment.