"save as" interface

1 回表示 (過去 30 日間)
Jakub Snopl
Jakub Snopl 2021 年 11 月 4 日
コメント済み: Walter Roberson 2021 年 11 月 4 日
Hi,
I trying to code in my MATLAB app a pop up "save as" interface, but it does not work and iam becoming desperate.
prompt = {'save as'};
dlgtitle = 'Input';
dims = [1 35];
definput = {'C:\myFolder\myFile.filename.txt'};
answer = inputdlg(prompt,dlgtitle,dims,definput);
path = string(answer);
hlavicka1 = '---------SOURADNICE BODU ORTODROMY---------';
hlavicka2 = 'c.b. U[D M S] V[D M S]';
fileID = fopen(path,'w');
fprintf(fileID,'%s\n',hlavicka1);
fprintf(fileID,'%s\n',hlavicka2);
...
Error call:
Error using fprintf
Invalid file identifier. Use fopen to generate a valid file identifier.

採用された回答

Steven Lord
Steven Lord 2021 年 11 月 4 日
Why not just use the uiputfile function included as part of MATLAB?
  2 件のコメント
Jakub Snopl
Jakub Snopl 2021 年 11 月 4 日
because i did not know that this function exist :D, thank you
Walter Roberson
Walter Roberson 2021 年 11 月 4 日
Either way, you should try to get accustomed to programming something along the lines of
[fileID, msg] = fopen(path, 'w');
if fileID < 0
error('Could not open file "%s" because "%s"', path, msg);
end
Even in cases where you are sure that the user returned something that looks like a valid file name in a valid directory, you can't be sure that the fopen() will work -- the disk might be out of space, the disk might be read-only, the user might not have write permission...

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLow-Level File I/O についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by