Matlab: Open and plot all files in register


Open and plot of all files in a register

(German) This plot is about to open and plot all files in a register with Matlab. First of all, all files with the format *.txt are opend and saved in files.

files = dir('*.csv');
For value = 2 just every second file is saved.

for i = 1:1:length(files)/value
    fid3{i}=files(i).name;
end

To sort these files by name you need to download "natsortfiles" from Matlab-Exchang:

fid3 = natsortfiles(fid3)
for i = 1:value:length(files) 
    fid = fopen(fid3{i});
    daten = textscan(fid,'%f %f','delimiter',',','headerlines',0');
    q1(:,i/value) = daten(1);
    q2(:,i/value) = daten(2);
end
fclose(fid);

In "textscan" with 'headlines',0 is the amount of rows are defined which are delited from the text file. The files from coulomn 1 are saved in q1 and from coulomn 2 are saved in q2.

Furthermore the files are opened and saved in a matrix and in a defined area x and y are defined.

%convert cell to matrix
q1=cell2mat(q1);
q2=cell2mat(q2);
%take a defined area
x = q1(650:1150,:);
y = q2(650:1150,:);

Now, the files are ready to to be shown. Therefor the function ColSpec is used for a colorspectra.

fig = figure(1)
hold on;
for i=1:1:length(files)
     h(i)=plot(x(:,i),y(:,i),'Color',ColSpec(length(x),i);
 end

Now the files are numbered and are depicted in the legende:

leg = num2str([1:1:length(files)]');
leg = strcat('Datei', leg);
legend(h2,leg,'location','EastOutside');





Kommentare

Beliebte Posts aus diesem Blog

Easy Plots in HTML/PHP with Google Charts

Matlab: 3D Coordinate System Rotations with Vectors

Matlab: Dijkstra methode - shortest way on gradient (small neighborhood)