How to read a file from a specific directory?
7 次查看(过去 30 天)
显示 更早的评论
I'll explain my question with an example.
Lets say I have 26 folders in my working directory named A to Z, and each of these folders have 10 sub-folders with names 1 to 10.
Now, in a function I am preparing, I want to access files in a particular folder, which is defined by the input arguments when i call the function.
If I wanted to point to a file named xyz in folder 5 in folder A, doing it manually on command window would be /A/5/xyz
In my function, A and 5 are defined by the input argument. I tried converting the input argument A and 5 to strings str_fol1 and str_fol2 and point to /str_fol1/str_fol2/xyz and /'str_fol1'/'str_fol2'/xyz but it dint work.
Can anyone guide me, as to how to point to a file when the path to it is being defined by input arguments in a function?
Thanks
0 个评论
采纳的回答
Chirag Gupta
2011-8-10
Use
full_filename = fullfile(str_fol1,str_fol2,filename);
6 个评论
sandy
2013-9-5
hi guys...i have a prob here...if i have a folder called 'MAIN',inside this sub folders from A TO Z,which contains many zip files...i need to access those zip files from each folder(A TO Z),and to unzip them..it is possible
更多回答(1 个)
Paulo Silva
2011-8-10
%assuming:
%folder is a string with just the folder name, ex A
%file is a string with just the file name
file=[folder filesep subfolder filesep file]
%code to read the file, it depends on the file type and format
1 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Filename Construction 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!