How to have a user select a file from a directory and then matlab automatically go into that folder and pull multiple files with the same name
조회 수: 37 (최근 30일)
이전 댓글 표시
I am trying to write code that allows a user to select a file from a directory and then automatically pull in multiple files within a subfolder that have 2 different names? i’m not sure the best way to go about this and would appreciate any help!
댓글 수: 0
답변 (1개)
Austin M. Weber
2024년 2월 9일
편집: Austin M. Weber
2024년 2월 9일
You can use the uigetdir function to prompt the user to select a file directory, and then you can use the dir function to get a structure array with all of the file names in that directory:
selected_dir = uigetdir();
files = dir(selected_dir);
% File names are stored in the name field, for example: files(3).name
Or, if you want the user to select a specific file, you can use uigetfile, which also saves the path of the file so that you can use it to access other files on that path:
[selected_file, file_path] = uigetfile();
Does this help?
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 File Operations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!