Read certain files from a directory in matlab?

Hello,
I have over 100 .mat files in a directory and I am wondering how can I read and plot some of them. For example the file names are like such:
XX11YZ08 , XX12YZ07, XX13YZ08, XX14YZ06, XX15YZ08, and so on...
I would like to read and plot the data from all the files whose name end with '08'.
Thanks a lot in advance

 채택된 답변

Daniele
Daniele 2013년 1월 25일
편집: Daniele 2013년 1월 25일

1 개 추천

Hi you can begin your m-file with dir() like
>_>filenames_in_mydirectory=dir()_
then create a cicle (for,while..)
in this cicle use string functions for comparing only last 2 character of the filename (before ".extension" obviously) with the string "08" and save the filenames that match with this condition in an array
after that use load()
mydata=load('myxxxyxylile08.mat'); and so plot data.
good luck

댓글 수: 4

Jay
Jay 2013년 1월 25일
편집: Walter Roberson 2022년 9월 14일
Thanks Daniele. I got it to read the specific files like such:
files = dir(fullfile('D:\MyFolder\', '*08.mat'))
L = length(files);
for i=1:L
file=files(i).name;
filepath = fullfile( 'D:\MyFolder\', file )
end
How do I now create an iterative loop which loads the data from each file and plots it on a single axes as overlaying plots?
start loop load, plot, hold on maybe clear variable or overwrite if you are running our of memory end loop
files = dir(fullfile('D:\MyFolder\', '*08.mat'))
This gets the file in the form of a structure, how to read the particular file from so that processing can be done on it further.
I have a folder with.tif files and I want to read some specific files so that I can do some processing with those further using geotiffread function.
Thanks.
does anyone know what to change if instead of files = dir(fullfile('D:\MyFolder\', '*08.mat'))
its files = dir ("filesname') but that reads two different file names that are need it and just need from from those two options

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

추가 답변 (1개)

Nike
Nike 2013년 1월 25일
편집: Nike 2013년 1월 25일

0 개 추천

Load the file within the 'for' loop and use the plot command followed by 'hold on' (use the hold on and plot within the loop)
if you want each to be in a different color, then you may have to create a string array with the colour codes and use them in the plot command with the (i),,,
Hope this helps
Cheers
Nike

카테고리

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

질문:

Jay
2013년 1월 25일

편집:

2022년 9월 14일

Community Treasure Hunt

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

Start Hunting!

Translated by