Why my matlab code cant load the directory that i wanted it to load instead read the weird file and say no directory

1 回表示 (過去 30 日間)
pdir='/Users/Phong/Desktop/RK4/'
load this
nameS=strcat(pdir,'InitCond30/','InitCond30_',int2str(run))
load(nameS);
it supposes to read /Users/Phong/Desktop/RK4/InitCond30/InitCond30_run
But it did not run that directory instead read the weird file and double letter like this
Error using load
Unable to read file
//UUsseerrss//PPhhoonngg//DDeesskkttoopp//RRKK44//IInniittCCoonndd3300//IInniittCCoonndd3300_ run:
No such file or directory.
Anybody has any idea why It reads and double the letter like that and how to fix it. Thanks
  5 件のコメント
Phong Pham
Phong Pham 2012 年 10 月 29 日
編集済み: Jan 2012 年 10 月 29 日
I generated the file in the folder InitCond30 with all run from 1 to 10
InitCond30 folder is located in /Users/Phong/Desktop/RK4/
It will create InitCond30_1, ....10
Now I want to load these files
pdir='/Users/Phong/Desktop/RK4/'
for run=1:10
if ic== 1
nameS=strcat(pdir,'InitCond30/','InitCond30_',int2str(run))
load(nameS);
end
end
The funny thing is they ran all from 1 to 9 and it did not run the last run 10.
[EDITED, Jan, code formatted - please do this by yourself, thanks!]
Matt J
Matt J 2012 年 10 月 29 日
Did you check what string nameS actually contains when run=10?

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

回答 (1 件)

Jan
Jan 2012 年 10 月 29 日
Loading directly to the workspace cab have unexpected results: What happens, if one of your MAT files contain a variable pdir? The result of the next iteration might be unexpected.
Therefore it is recommended to store the output of LOAD in a variable:
Data = load(nameS)
or Data{run} or whatever. Maybe this would solve your problem, but even if not, it is a good method to improve the quality of programs.

カテゴリ

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