handling filename containing spaces
21 ビュー (過去 30 日間)
古いコメントを表示
I am using the following code to load a data file [Windows environment]:
FileName = uigetfile('*.TAB','Select a TAB file.');
Frames = dlmread(FileName_in,'\t');
Most of the files have names such as foo_two.tab or foo-two.tab Some contain spaces, such as foo two.tab
I have tried both strcat and regexp to insert single quotes at the beginning and end of the filename string but these are ignored by the dlmread function.
Any tips or suggestions would be appreciated.
採用された回答
Jan
2012 年 3 月 16 日
Matlab's fopen handles filenames containing spaces without any problems. Do not enclose them in quotes or double quotes.
If you have any problems, there must by another reason.
3 件のコメント
Gordon Campbell
2021 年 12 月 1 日
Hi Jan,
Has this changed since 2012?
I tried fopen C:\New Folder and got "Error using fopen Invalid permission."
Whereas when I tried C:\NewFolder, I had no problem.
Stephen23
2021 年 12 月 1 日
編集済み: Stephen23
2021 年 12 月 1 日
"Has this changed since 2012? "
Nope. But based on your example code you are using command syntax, which a) will cause your filepath to be interpreted as two separate text inputs to FOPEN, and b) is not very useful for FOPEN anyway.
You should be using function syntax (and forget about command syntax unless debugging).
その他の回答 (1 件)
Sean de Wolski
2012 年 3 月 16 日
Ahh!
Difference between FileName and FileName_in. The issue has nothing to do with spaces.
参考
カテゴリ
Help Center および File Exchange で Workspace Variables and MAT Files についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!