MATLAB Answers

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

1 view (last 30 days)
Mohammed alfath Ahmed
Mohammed alfath Ahmed on 15 Sep 2019
Answered: Walter Roberson on 15 Sep 2019
Text='hello' [file, path] =uiputfile('text. Txt')

  1 Comment

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

Sign in to comment.

Answers (1)

Walter Roberson
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.

Sign in to answer this question.

Tags