From: Amy Clare on
I am trying to create a graph showing multiple datasets of the same type of data in the same format from files currently in a .txt or.dat format. I also have them in excel format. The datasets represent a data value vs time given in the same units in all files.

However the datasets are not all the same length (that is the point...) and the time at which a given data point is recorded is not the same from file to file.

I want to be able to carry out this same procedure for a variable number of files and data types vs time and reckon an m-file is probably the best way to create a regime in which to do this?

It's driving me mad as programming does not come naturally to me! Please help!
From: Rob Campbell on
So each data file contains two columns? One with time and with your value? If that's the case then it's pretty straightforward. Yes, you need to write a function. The easiest thing is probably to read in the text files. You would do something like this:

D=dir('*.txt'); %find all text files in the current directory

clf %create empty figure window
hold on

for ii=1:length(D) %Loop to process each file in turn
f=fopen(D(ii).name);

%Now you run commands to extract the data; see textscan
%if you have a header, you may need to ignore the first few lines.

fclose(f); %close the text file

plot(timeData,dataValues,'-o')
end
hold off

> However the datasets are not all the same length (that is the point...) and the time at which a given data point is recorded is not the same from file to file.

That doesn't matter at all if you have stored the times in the files. The sort of routine outlined above would just handle that naturally.