Hey Experts,
I want to select a .txt file from a directory. In this directory there is only one .txt file among a bunch of image files. Each time the name of the textfile is different. So I want something like: fopen *.txt I looked everywhere but I cannot find a solution for this on first sight easy problem.
Many thanks! Marten

 채택된 답변

Image Analyst
Image Analyst 2014년 3월 26일
편집: Image Analyst 2014년 3월 26일

1 개 추천

filePattern = fullfile(yourFolder, '*.txt');
textFiles = dir(filePattern);
If length(textFiles) == 1 then you know there's just one and you can grab that one. If the length > 1 then you might have to let the user select it with uigetfile() or else somehow figure out which one you want from the filename.

댓글 수: 1

Marty Dutch
Marty Dutch 2014년 3월 26일
Thanks for your prompt repsonse. This was the trick I needed!
Marten

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

추가 답변 (1개)

nl2605
nl2605 2014년 3월 26일

0 개 추천

I am not sure if this is the simplest way. But you can use 'uigetfile'. Here you can use the .*txt filter. And then use the filename to open the text file.

카테고리

도움말 센터File Exchange에서 Data Import and Analysis에 대해 자세히 알아보기

태그

질문:

2014년 3월 26일

편집:

2014년 3월 26일

Community Treasure Hunt

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

Start Hunting!

Translated by