change workdir and open file
2 ビュー (過去 30 日間)
古いコメントを表示
[ afile workdir ] = uigetfile( '*.dat','Select DAT-file' );
shortfilename = strrep( afile, '.DAT', '' );
cd( workdir );
fid = fopen( afile );
Whenever I run this code the first time, and select a file that is in another directory (not my workdir or a path that is added) I get an error about Matlab not able to open the file. At that point, Matlab's Current Folder window switches to the directory where the DAT file is. When I run it again, it works like it is supposed to.
How can I fix this issue? So what do I need to change that whenever I select a file that is not in a folder that is my workdir or added path, that it switches the workdir to that directory and opens the file...
1 件のコメント
Hin Kwan Wong
2011 年 12 月 1 日
try
fid = fopen([workdir,afile]);
instead
Also, I am worried about the fact that you removed the extension with strrep when asking matlab to do fopen. That can cause problems.
採用された回答
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Introduction to Installation and Licensing についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!