Matlab open file name from parts.

2 views (last 30 days)
Sjoerd
Sjoerd on 31 Oct 2016
Answered: KSSV on 31 Oct 2016
Hi,
I've been looking around an I cannot really find a proper way to do this. Basically, I've got a script where I open a specific file name each time. The specifics are not important, but for each data point I've got two data files. A raw data file and a callibration data file. Right now it prompts a window where I can open my data file, then it opens a function I wrote where it asks for the callibration file. Then it does some calculations, giving me my data.
The thing is, right now I've got quite a lot of data files I want to evaluate. And it would save a lot of time if I didn't have to do this one by one. Luckily, I've given my files sensible names. That is, all exactly the same with a timestamp and a number to refer wich data series it is. So the measurement I've done on Sprite gives has the file name sprite_quarts_160923_#1 with the associated callibration matrix cal_empty_quarts_160923_#1.
I'd like to modify my script such that it opens sprite_quarts_yymmdd_#s. for all of my data points. So I'm guessing I want to tell it to open sprite_quarts_yymmdd_#s. And then loop it such that for each iteration it opens the next file. So let yy loop from 16 to 16, mm from 09 to 10 and dd from 01 to 31.
Would it be possible to ask Matlab to open partial filenames like this? Like
for yy = 16
for mm = 10:12
for dd = 01:31
A = importdata(sprite_quarts_yymmdd_#s)
end
end
end
Obviously the above thing does not really compile. But just to illustrate the idea. Also, I'm not that interested in efficiency. I don't care about having a beautiful code at this stage :)
Thanks for the answer

Answers (1)

KSSV
KSSV on 31 Oct 2016
You can access all the files in your directory as below:
% Get all text files in the current folder
files = dir('*.txt'); % txt files
% Loop through each
for id = 1:length(files)
% Get the file name
fname = files(id).name ;
%%do what you want
% data = importdata(fname) ;
end

Categories

Find more on File Operations in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!