1

I am working on an assignment using an oscilloscope and measuring signals. I have written a program to automatically set parameters for an oscilloscopes output data to write a specific number of files(lets call that N). I have all of these files in a document.

I want to import these files into Matlab, extract the necessary data, and plot them in real time in one second intervals (between file to file).

Example run

Write twelve files (N=12) into documents/development create a while loop that will escape when any key is entered use textread to read the each file (i do not have an updated version of matlab so I cant use textscan). plot the data
move to next file end

The problem is that the filenames are not consistent, they are all named according to the time it took to process them so they differ by different amounts everytime (stream-july-10-10:12 , stream-july-10-10:13, stream-july-10-10:15 for example.

So I need a way of moving to the next file and plotting it without having to actually go by the name of the file.

I know its alot but any help or any point in the right direction would be much appreciated.

Thanks, Jmitch

JonathanMitchell
  • 400
  • 1
  • 2
  • 12

2 Answers2

2

dir returns the last modified date as a character array in the date field and as a serial date in the datenum field. You can sort the datenum array and use the returned indices to load in your data.

Basically:

A = dir(mypath); % You can also add filter criteria here, per the documentation
[~,idx] = sort([A.datenum]);

for ii = 1:12
    filetoload = fullfile(mypath,A(idx(ii)).name); % Build absolute path to your file
    % Load in file
end
sco1
  • 12,154
  • 5
  • 26
  • 48
0

I think the function dir is what you are looking for. It can list you the contents of the current matlab folder and supports wildcards. With that you should be able to get all the paths of files in a string array, then loop over that array.

Documentation for dir.

This question might be of interest, too: How to get all files under a specific directory in MATLAB?

Community
  • 1
  • 1
sobek
  • 1,386
  • 10
  • 28