Reading From Different Directories in a for loop (fopen from different directories)
1 回表示 (過去 30 日間)
古いコメントを表示
Hi,
My problem is,
I can not read the file from different directory/folder My file name is same all the time . It is " kEG1____1.gid ".(It is atext file)
C:\......Case_Set_1.135\simulation.dir\kEG1____1.gid
C:\......Case_Set_1.136\simulation.dir\kEG1____1.gid
C:\......Case_Set_1.137\simulation.dir\kEG1____1.gid
...
I can read and process the text file individually with the code that Mr/Ms Per Isakson wrote from this forum.It uses fopen(..9) for opening the file.The link is here. http://www.mathworks.com/matlabcentral/answers/37437-textscan-reading-after-a-specified-term-or-a-row-and-writing-matrix )
But the problem is all the files located in different directories.
C:\......Case_Set_1.135\simulation.dir\kEG1____1.gid
C:\......Case_Set_1.136\simulation.dir\kEG1____1.gid
C:\......Case_Set_1.137\simulation.dir\kEG1____1.gid
...
I tried to obtain directory names with sprintf but it gives an error.
for i=136:137
fullFileName=sprintf('C:\Users\KARTAL\Dropbox\CaseDenemeler\BWF25PRE_2000\boost\135-143set.Case_Set_1.1%d\simulation.dir\kEG1____1.gid',i)
end
But it gives " Invalid escape sequence appears in format string. See help sprintf for valid escape sequences." which I think it is an backslash forwardslash error..
But I could not solve the problem.
anyone can help me about this situation.
Best Regards.
0 件のコメント
採用された回答
per isakson
2012 年 5 月 6 日
There is a function in the FEX, Recursive directory listing - Enhanced RDIR, which I guess will help you out.
The call will be something like
sad = rdir( 'root_something\**\kEG1*1.gid' )
maybe
sad = rdir( 'c:\Users\KARTAL\Dropbox\CaseDenemeler\BWF25PRE_2000\boost\135-143set.Case_Set_1.13*\**\kEG1*1.gid' )
There are two rdir in the FEX. I intended to link to Recursive directory listing. That is the one that has become part of my Matlab. However, I guess either one will do the job.
その他の回答 (2 件)
Image Analyst
2012 年 5 月 6 日
Simple solution: use forward slashes instead of backslashes. Even Windows handles them just fine:
fullFileName=sprintf('C:/Users/KARTAL/Dropbox/CaseDenemeler/BWF25PRE_2000/boost/135-143set.Case_Set_1.1%d/simulation.dir/kEG1____1.gid',i)
Another tip: Use genpath() to get a list of all subfolders. Perhaps this may come in useful in the event that you don't know all the subfolder names in advance.
Walter Roberson
2012 年 5 月 6 日
fullFileName=sprintf('%s%d%s', 'C:\Users\KARTAL\Dropbox\CaseDenemeler\BWF25PRE_2000\boost\135-143set.Case_Set_1.1', i, '\simulation.dir\kEG1____1.gid')
end
参考
カテゴリ
Help Center および File Exchange で Search Path についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!