Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- clc, clear, close all
- % Files in folder plotter - By Jes Linnet
- % Can analyse a folder and plot all datafiles found in the folder, omitting subfolders.
- % Users must specify data columns, field delimiter, units, labels, file extension and import line offsets.
- % Users can specify subplot dimensions (cols=rows=1 corresponds to no subplot).
- % If more than cols*rows files in folder, additional plots with cols*rows subplots created.
- % spreadfigures.m from mathworks website is required to evenly spread and display all figures on desktop, last line can be omitted.
- % % % Setup % % %
- directory='C:\Users\Administrator\Dropbox\Anders og Jes\Sem 10\Master Project\Sweeps\Zahner';
- ext='.txt'; % choose the imported files' extension
- rowoffset=19; % choose how many rows to skip when beginning file import
- coloffset=0; % ...same for columns
- delim='\t'; % field delimiter, a string. '\t' = tab. ' ' = space. ',' = comma
- xunit=1; % fix axis units, x and y data * 1/unit
- yunit=10^6;
- xdata=3; % specify which column contains x and y data in files
- ydata=4;
- labelx='Voltage (V)'; % label x and y data
- labely='Current (uA)';
- cols=1; % specify maximum number of columns/rows in subplots
- rows=1;
- % % % Folder analysis % % %
- addpath(directory); % add folder to matlab path
- d=dir(directory); % store directory in struct
- k2=[]; % start with empty array
- for k=1:length(d) % locate which files to plot (not empty and contains extension)
- fname=d(k).name; % store k'th filename in string
- containtxt=strfind(fname,ext); % find extension in filename
- if (d(k).bytes > 0)&&(isempty(containtxt)==0)
- k2=[k2 k]; % extend k2 vector with data file fields
- end
- end
- % % % Plotting datafiles % % %
- figure; % k2 now contains the fields of 'd'...
- count=0; % ...which
- for k=k2 % check d out in variables window (remove folders)
- if(count >= rows*cols) % begin new figure when first is filled
- figure;
- count = 0;
- end
- fname=d(k).name; % store k'th filename in string
- containtxt=strfind(fname,ext); % find extension in filename
- if (d(k).bytes > 0)&&(isempty(containtxt)==0) % if not folder and contains extension
- data=dlmread(fname,delim,rowoffset,coloffset); % store data from k'th file, delim delimited, skip rowoffset lines,
- IV=[data(:,xdata),data(:,ydata)]; % extract x and y vectors from data array
- count=count+1; % increment count for subplot positions
- subplot(rows,cols,count) % move to next subplot
- plot(IV(:,1)*xunit,IV(:,2)*yunit,'k','LineWidth',2) % plot in subplot
- title(fname); % filename = subplot title
- xlabel(labelx) % set labels
- ylabel(labely)
- grid
- end
- end
- spreadfigures % display results!
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement