Advertisement
Guest User

folder plotter

a guest
Jul 12th, 2017
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 3.25 KB | None | 0 0
  1. clc, clear, close all
  2. % Files in folder plotter                    - By Jes Linnet
  3.  
  4. % Can analyse a folder and plot all datafiles found in the folder, omitting subfolders.
  5. % Users must specify data columns, field delimiter, units, labels, file extension and import line offsets.
  6. % Users can specify subplot dimensions (cols=rows=1 corresponds to no subplot).
  7. % If more than cols*rows files in folder, additional plots with cols*rows subplots created.
  8. % spreadfigures.m from mathworks website is required to evenly spread and display all figures on desktop, last line can be omitted.
  9.  
  10. % % % Setup % % %
  11. directory='C:\Users\Administrator\Dropbox\Anders og Jes\Sem 10\Master Project\Sweeps\Zahner';
  12. ext='.txt';                         % choose the imported files' extension
  13. rowoffset=19;                       % choose how many rows to skip when beginning file import
  14. coloffset=0;                        % ...same for columns
  15. delim='\t';                         % field delimiter, a string. '\t' = tab. ' ' = space. ',' = comma
  16. xunit=1;                            % fix axis units, x and y data * 1/unit
  17. yunit=10^6;
  18. xdata=3;                            % specify which column contains x and y data in files
  19. ydata=4;                            
  20. labelx='Voltage (V)';               % label x and y data
  21. labely='Current (uA)';              
  22. cols=1;                             % specify maximum number of columns/rows in subplots
  23. rows=1;                            
  24.  
  25. % % % Folder analysis % % %
  26. addpath(directory);                 % add folder to matlab path
  27. d=dir(directory);                   % store directory in struct
  28. k2=[];                              % start with empty array
  29. for k=1:length(d)                   % locate which files to plot (not empty and contains extension)
  30.     fname=d(k).name;                % store k'th filename in string
  31.     containtxt=strfind(fname,ext);  % find extension in filename
  32.     if (d(k).bytes > 0)&&(isempty(containtxt)==0)
  33.         k2=[k2 k];                  % extend k2 vector with data file fields  
  34.     end
  35. end
  36.  
  37. % % % Plotting datafiles % % %
  38. figure;                             % k2 now contains the fields of 'd'...
  39. count=0;                            % ...which
  40. for k=k2                            % check d out in variables window (remove folders)    
  41.     if(count >= rows*cols)          % begin new figure when first is filled
  42.         figure;
  43.         count = 0;
  44.     end
  45.     fname=d(k).name;                % store k'th filename in string
  46.     containtxt=strfind(fname,ext);  % find extension in filename
  47.     if (d(k).bytes > 0)&&(isempty(containtxt)==0) % if not folder and contains extension
  48.         data=dlmread(fname,delim,rowoffset,coloffset); % store data from k'th file, delim delimited, skip rowoffset lines,
  49.         IV=[data(:,xdata),data(:,ydata)]; % extract x and y vectors from data array
  50.         count=count+1;              % increment count for subplot positions
  51.         subplot(rows,cols,count)    % move to next subplot
  52.         plot(IV(:,1)*xunit,IV(:,2)*yunit,'k','LineWidth',2) % plot in subplot
  53.         title(fname);               % filename = subplot title
  54.         xlabel(labelx)              % set labels
  55.         ylabel(labely)
  56.         grid
  57.     end
  58. end
  59. spreadfigures                       % display results!
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement