フィルターのクリア

eval fails with load when path or filename has space(s)

15 ビュー (過去 30 日間)
John Petersen
John Petersen 2012 年 12 月 18 日
If I run
load [dirpath filename]
and dirpath or filename has a space, it loads the file just fine. But if I use
eval(['load ' [dirpath filename]]);
Matlab prints "Unable to read file .... No such file or directory".
I noticed that if I type
dir C:\mydir\
then tab, the path is printed with a ' whereever there is a space. But I'm not sure how to mimic that. Are spaces in path or filename in this instance a limitation of Matlab, or is there a solution?

採用された回答

Walter Roberson
Walter Roberson 2012 年 12 月 18 日
Like we always say: don't use eval()
Question: are you sure you are using
load [dirpath filename]
and not
load( [dirpath filename] )
??
Also, have you considered using fullfile() ?
  2 件のコメント
John Petersen
John Petersen 2012 年 12 月 18 日
Good point. Yes, I was using load with (). and what was I thinking not to remove eval??????
Thanks Walter.
Image Analyst
Image Analyst 2012 年 12 月 18 日
There is a difference in the way functions handle strings when they are called with the function form (with parentheses) vs. the command line form (no parentheses). Walter would be better than me at explaining why. Anyway, you can use sprintf() and three or 4 ' to write a ' into a string.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeFile Operations についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by