Import multiple ftext files in MATLAB_ Names of files are dates

Hello all,
I have a folder with different back up measurements (Wind, Tide height,...)in different files from 31/12/2009 till 31/12/2010 in .txt format. The file names are in a date format that matlab cannot recognize. For example the TIDE Height file for 31/12/2009 is '091231_000000_22168_TIDE_HEIGHT.txt' and the TIDE Height file for 31/12/2010 is named ' 101231_000000_22168_TIDE_HEIGHT.txt' and so on.
I want to create a loop in MATLAB to scan the files of this folder and only read the files of TIDE Height measurements. Then combine them in one matrix (1439,365) because I have measurements every minute of every day and every day of the year.
Thank you for your much appreciated help.

 Accepted Answer

i fixed it with this
for k=100101:100102
textFilename=sprintf('%d_000000_22168_TIDE_HEIGHT.txt',k);
delimiter = '\t';
startRow = 2;
formatSpec = '%{dd/MM/yyyy}D%{HH:mm:ss}D%f%*s%[^\n\r]';
fileID = fopen(textFilename,'r');
dataArray = textscan(fileID, formatSpec, 'Delimiter', delimiter, 'HeaderLines' ,startRow-1, 'ReturnOnError', false);
fclose(fileID);
Date = dataArray{:, 1};
Time = dataArray{:, 2};
TIDE_HEIGHTMETER(:,k-100100)= dataArray{:, 3};
clearvars textFilename delimiter startRow formatSpec fileID dataArray ans numfiles;
end
but I need to write a loop for each month

More Answers (0)

Categories

Find more on Data Import and Analysis in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!