Vissenbot
Vissenbot

Reputation: 227

Automatic file opening in MATLAB

I'm running a program on magnetometry. I have a file which contains over 10 text files, each containing the data (amplitude vs frequency) at a precise magnetic field value.

My program then reads each of those files, plotting the data, making a fit over those and then I use this fit to find the magnetic field depending on the distance of the frequency between 2 amplitude peaks (that's just theory, it's not necessary to understand this part).

All I want is some lines of code that would open all the files in the specified directory and let me use the datas (i.e. data = importdata(filenames{i},delimiterIn,headerlinesIn);)

And later on I have a line that ask the user which data file he wants to open, and it gives back the magnetic field value.

So I need to use two folders : the one containing the data to create my fit and equations. And the one containing whatever data file the user wants to open to find the magnetic field applied while getting data.

Upvotes: 1

Views: 966

Answers (1)

bla
bla

Reputation: 26069

It isn't clear from the question if you want the user to do this interactively or not, so I assumed you do. To select a folder you can use uigetdir , for example:

d = uigetdir('C:\');

will displays directories on the C: drive to select from, etc... Similarly, to select all the files in that folder you can use dir. For example, if you want to pick out all the TXT files in a folder that the user selects:

 d = uigetdir(pwd, 'Select a folder');
 files = dir(fullfile(d, '*.txt'));

Upvotes: 4

Related Questions