MATLAB Answers

Can Matlab search through the current directory to find and import a file?

조회 수: 24(최근 30일)
I have some scripts that do data analysis and I am hoping to write some preliminary code to go through the current folder and find a .csv file and then import it and then I would like to go through another folder and search for a '...SizeChem.dat' file without knowing the full name of the file only knowing that it is the only file that ends with SizeChem.dat. I am not sure if this is possible or not but would greatly appreciate the help.

  댓글 수: 0

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

채택된 답변

Cam Salzberger
Cam Salzberger 13 Jun 2019
Hey Noah,
You can use the dir function to get information on the contents of a folder. You can use wildcards (* or **) to match multiple possible files. For example, dir('*.csv') will match all CSV files in the current directory. And you could do dir('path/to/other/dir/*SizeChem.dat') to match your other file (if you know the folder it should be in). If you need to search through multiple folders, you can simply loop through them, checking if any matches were found (with dir or even exist).

  댓글 수: 0

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

추가 답변(0개)

Community Treasure Hunt

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

Start Hunting!

Translated by