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
Jan 2012년 3월 16일

3 개 추천

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

Philip
Philip 2012년 3월 16일
Jan,
Thanks. You are right.
I added the data file to a sub-directory then proceeded to analyze the data. I pulled a novice mistake of forgetting to add the sub-directory to my path.
Once that was done everything worked fine.
Gordon Campbell
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
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
Sean de Wolski 2012년 3월 16일

1 개 추천

Ahh!
Difference between FileName and FileName_in. The issue has nothing to do with spaces.

댓글 수: 1

Philip
Philip 2012년 3월 16일
Sorry. I had finger failure. The correct code is
FileName_in = uigetfile('*.TAB','Select a TAB file.');
Frames = dlmread(FileName_in,'\t');

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Characters and Strings에 대해 자세히 알아보기

제품

질문:

2012년 3월 16일

편집:

2021년 12월 1일

Community Treasure Hunt

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

Start Hunting!

Translated by