How to read a file from a specific directory?

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

 채택된 답변

Chirag Gupta
Chirag Gupta 2011년 8월 10일

2 개 추천

Use
full_filename = fullfile(str_fol1,str_fol2,filename);

댓글 수: 6

Ashish
Ashish 2011년 8월 10일
Hi Chirag,
Thanks that was useful.
Now I am able to create a string with the path to the required file. But I am not able to use it to access the required file.
I can read it by
A=dlmread('C:\Users\Ashish\Documents\Programming\MATLAB\test_files\110808\data1105',' ')
but after I use fullfile and have the path in lets say 'f', the statement
A=dlmread('f',' ') doesn't work.
where f is a string C:\Users\Ashish\Documents\Programming\MATLAB\test_files\110808\data1105
Chirag Gupta
Chirag Gupta 2011년 8월 10일
use dlmread(f,''); f is already a string you don't need single quotes around it
Ashish
Ashish 2011년 8월 11일
Thanks! It worked.
Pamela
Pamela 2013년 5월 31일
Thank you Ashish for asking and Chirag for answering! This was the one missing key that will make my life much easier :)
Jan
Jan 2013년 5월 31일
@Pamela: If this question and answer help you, you can vote for it.
sandy
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
Paulo Silva 2011년 8월 10일

0 개 추천

%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

Tulips
Tulips 2012년 10월 20일
편집: Tulips 2012년 10월 20일
hi Silva, can you help me how to display let's say 'the output recognized as bump sign'. the bump sign is red as 1.jpg in a folder. in that folder consist of 10 images with .jpg extension. How cn I rename 1.jpg of the output as bump sign?

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

카테고리

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

제품

태그

질문:

2011년 8월 10일

Community Treasure Hunt

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

Start Hunting!

Translated by