├── .gitignore ├── Contour ├── Version History.md ├── contourpolefigures.m ├── gaussiancontour.m ├── initcrystaldirections.m ├── kambcontour.m ├── lowerhemisphere.m ├── makepolefigures.m ├── rotationmatrix2crystaldirections.m ├── rotationmatrix2quartzdirections.m ├── test-quartz.txt └── testcontourstereogram.m ├── Drex.m ├── Images ├── _Figure_SyntheticOlivine.png └── _Figure_SyntheticOlivineFlows-01.png ├── License.md ├── README.md ├── colormaps ├── algae.m ├── coolwarm.m ├── hklcolor.m ├── rdylbu.m ├── test_colormaps.m └── virus.m ├── dispstat ├── dispstat.m ├── license.txt └── test_dispstat.m ├── export_fig ├── .gitignore ├── .ignore │ ├── ghostscript.txt │ └── gs_font_path.txt ├── ImageSelection.class ├── ImageSelection.java ├── LICENSE ├── README.md ├── append_pdfs.m ├── copyfig.m ├── crop_borders.m ├── eps2pdf.m ├── export_fig.m ├── fix_lines.m ├── ghostscript.m ├── im2gif.m ├── isolate_axes.m ├── pdf2eps.m ├── pdftops.m ├── print2array.m ├── print2eps.m ├── read_write_entire_textfile.m ├── user_string.m └── using_hg2.m └── functions ├── cmapscale.m ├── euler2orientationmatrix.m ├── gcolor.m ├── lambertprojection.m ├── orientationmatrix2euler.m ├── polenet.m └── wrap.m /.gitignore: -------------------------------------------------------------------------------- 1 | Output/* -------------------------------------------------------------------------------- /Contour/Version History.md: -------------------------------------------------------------------------------- 1 | Version 1.0. 2 | - First working Version. 3 | - Includes only Kamb cutoff window. 4 | 5 | Version 1.1. 6 | - CJT, March 19, 2015 7 | - Add in the Gaussian window to further smooth the contour plots. -------------------------------------------------------------------------------- /Contour/contourpolefigures.m: -------------------------------------------------------------------------------- 1 | function [hFig] = contourpolefigures(eulerAngles,mineral,method,varargin) 2 | % For an input of euler angles (Bunge convention) and a mineral name 3 | % ('olivine' or 'quartz'), this function plots the pole figures using Kamb 4 | % or Gaussian contouring. The function is currently setup only for 5 | % non-polar data, and calculates the density in a single hemisphere. 6 | % 7 | % Input parameters: eulerAngles is an Nx3 matrix of Bunge convention Euler 8 | % angles in radians. 9 | % 10 | % mineral is 'olivine' or 'quartz' and determines which crystallographic 11 | % axes are plotted. Olivine pole figures include [100], [010], and [001] 12 | % directions. Quartz pole figures include c-axes, a-axes, and poles to m,r, 13 | % and z planes. 14 | % 15 | % method is the contouring method, and is either Kamb or Guassian 16 | % 17 | % The figure handle can be input as varargin. Otherwise a new figure is 18 | % created. Addition variable input arguments are the stereogram hemisphere, 19 | % the number of points to use in each dimension of the stereogram, and 20 | % options for the colormap. 21 | % 22 | % 23 | % Version 1.0. CJT Jan 27, 2015. First working version. 24 | % Version 1.01 CJT Feb 4, 2015. Included optional figure handle input 25 | % Version 1.1 CJT Mar 18, 2015. Added gaussian smoothing 26 | % 27 | %... default coordinate frame 28 | % %%% %%% 29 | % %%% %%% 30 | % 31 | % %%% %%% 32 | % 33 | % %%% %%% 34 | % % +z +x 35 | % %%% %%% 36 | % 37 | % %%% %%% 38 | % 39 | % %%% %%% 40 | % 41 | % %%% +y %%% 42 | 43 | % Dependencies: 44 | % addpath('/Volumes/Research/MATLAB/'); 45 | % addpath('/Volumes/Research/MATLAB/EulerAngleFunctions/'); 46 | % addpath('/Volumes/Research/MATLAB/Stereogram/'); 47 | % addpath('/Volumes/Research/MATLAB/cmapscale/'); 48 | % addpath('/Volumes/Research/MATLAB/colormaps/'); 49 | % addpath('/Volumes/Research/MATLAB/dispstat/'); 50 | % dispstat('','init'); % One time only initialization 51 | 52 | 53 | %% Check inputs 54 | narginchk(2,7); % requires 2 argument, with 3 additional optional arguments 55 | 56 | % check eulerAngles is Nx3 57 | [~,nDim] = size(eulerAngles); 58 | if nDim ~= 3 59 | error('eulerAngles must be input as Nx3 matrix'); 60 | end 61 | 62 | % check range of eulerAngles 63 | maxE = max(eulerAngles,[],1); 64 | minE = min(eulerAngles,[],1); 65 | if any(maxE > 2*pi) || any(minE < 0) || maxE(2) > pi 66 | error('Expected euler angles be in range 0 < eulerAngles(:,1), eulerAngles(:,3) < 2pi and 0 < eulerAngles(:,2) < pi'); 67 | end 68 | 69 | % validate method of contouring input 70 | validatestring(method,{'Kamb','Gaussian'}); 71 | 72 | % Parse input and define default values 73 | %... colormap options for cmapscale.m 74 | ColorOpts.colorRamp0 = hklcolor(256); 75 | ColorOpts.nTics = 3; 76 | ColorOpts.centerVal = []; 77 | ColorOpts.factor = 0.8; 78 | 79 | optArgs = {1,'upper',151,ColorOpts}; 80 | nArgsIn = find(~cellfun(@isempty,varargin)); 81 | 82 | 83 | %...copy cells from varargin to optArgs 84 | optArgs(nArgsIn) = varargin(nArgsIn); 85 | 86 | [f,hemisphere,nSpherePoints,ColorOpts] = optArgs{:}; 87 | 88 | 89 | %% Start Calculation 90 | % Convert euler angles to unit vectors 91 | g = euler2orientationmatrix(eulerAngles); % g is arranged as nx9 vector. 92 | 93 | % convert dir cosines to relevant crystal directions 94 | [CrystalDirections,nDirections] = rotationmatrix2crystaldirections(g,mineral); 95 | 96 | % Calculate points on the sphere 97 | [SphereProj] = lambertprojection(nSpherePoints,hemisphere); 98 | 99 | 100 | 101 | % operate on each crystal direction 102 | for i = 1:nDirections 103 | % convert axes to lower hemisphere (find antipodes) 104 | % CrystalDirections{i}.unitVectors = lowerhemisphere(CrystalDirections{i}.unitVectors); 105 | 106 | % Get Kamb contours levels 107 | switch method 108 | case 'Kamb' 109 | CrystalDirections(i) = kambcontour(CrystalDirections(i),SphereProj); 110 | 111 | 112 | case 'Gaussian' 113 | CrystalDirections(i) = gaussiancontour(CrystalDirections(i),SphereProj); 114 | 115 | end 116 | 117 | end 118 | 119 | % Make figure 120 | hFig = figure(f); clf 121 | hFig = makepolefigures(CrystalDirections,mineral,SphereProj,hFig,ColorOpts); 122 | 123 | %% LINT: This will plot all datapoints in 3D 124 | % figure(3); clf 125 | % subplot(1,3,1) 126 | % scatter3(CrystalDirections{1}.unitVectors(:,1),CrystalDirections{1}.unitVectors(:,2),CrystalDirections{1}.unitVectors(:,3)) 127 | % xlabel('x') 128 | % axis equal 129 | % 130 | % subplot(1,3,2) 131 | % scatter3(CrystalDirections{2}.unitVectors(:,1),CrystalDirections{2}.unitVectors(:,2),CrystalDirections{2}.unitVectors(:,3)) 132 | % xlabel('x') 133 | % axis equal 134 | % 135 | % subplot(1,3,3) 136 | % scatter3(CrystalDirections{3}.unitVectors(:,1),CrystalDirections{3}.unitVectors(:,2),CrystalDirections{3}.unitVectors(:,3)) 137 | % xlabel('x') 138 | % axis equal 139 | 140 | % scatter3(CrystalDirections.data{1}.x(:),CrystalDirections.data{1}.y(:),CrystalDirections.data{1}.z(:)) 141 | 142 | %% 143 | % keyboard 144 | 145 | end 146 | 147 | 148 | 149 | 150 | -------------------------------------------------------------------------------- /Contour/gaussiancontour.m: -------------------------------------------------------------------------------- 1 | function Directions = gaussiancontour(Directions,SphereProj) 2 | % Calculate a Gaussian smoothed kernel of the input Directions over the 3 | % points given in SphereProj. This function uses the absolute value of the 4 | % cosine of the angle to give the acute angle between the grid points and 5 | % the data. 6 | % 7 | % Directions is a structure that contains the Nx3 unitVectors field. 8 | % Directions also contains nData for the number of data and multiplicity, 9 | % which gives number of equivalent directions. 10 | % SphereProj is also a structure that contains the x, y, and z 11 | % coordinates of the grid on which the Gaussian smoothing is calculated. 12 | % 13 | % For more information, see: Robin, P. Y. F., & Craig Jowett, E. (1986). 14 | % Computerized density contouring and statistical evaluation of orientation 15 | % data using counting circles and continuous weighting functions. 16 | % Tectonophysics, 121(2), 207-223. 17 | % 18 | % 19 | % parse inputs 20 | gridVectors = [SphereProj.x(:), SphereProj.y(:), SphereProj.z(:)]; 21 | [nSpherePoints,~] = size(SphereProj.X); 22 | 23 | % Calculate window parameter, k 24 | nData = Directions.nData; 25 | m = Directions.multiplicity; 26 | k = 2*(1+m*nData/9); % Robin and Jowett, Table 3 pdf pg 9 27 | 28 | % k = k/2 29 | % keyboard 30 | 31 | maxData = 100000; 32 | % keyboard 33 | if nData*m <= maxData && numel(SphereProj.x) < 3000000 34 | % vectorized version (much faster) 35 | 36 | % Calculate the angle between the spherePoint and each of the data points 37 | cosAng = gridVectors*Directions.unitVectors'; 38 | clear gridVectors 39 | 40 | fprintf(1,'Vectorized angular distance calculation for %s \n',Directions.name); 41 | 42 | % calculate the continuous weighting function 43 | counts = exp(k*(abs(cosAng)-1)); % absolute value ensures acute angle is always returned 44 | clear cosAng 45 | 46 | % w is a nSpherePoints x nData matrix. Sum along the rows to calculate 47 | % the count value for each grid point 48 | counts = sum(counts,2); 49 | 50 | 51 | else 52 | % loop for large datasets 53 | counts = zeros(size(gridVectors(:,1))); 54 | dispstat(sprintf('Calculating angular distances for %s: \t',Directions.name),'keepthis'); 55 | for i = 1:nSpherePoints 56 | dispstat(sprintf('Progress %02.1f%%',100*i/nSpherePoints)); 57 | 58 | % operate on a subset of sphere points (partially vectorized) 59 | idx = (i-1)*nSpherePoints + 1:(i-1)*nSpherePoints + nSpherePoints; 60 | 61 | % calculate dot product for this subset 62 | gridV = gridVectors(idx,:); % vector of grid point 63 | cosAng = gridV*Directions.unitVectors'; 64 | 65 | % calculate the continuous weighting function 66 | tmp = exp(k*(abs(cosAng)-1)); % absolute value ensures acute angle is always returned 67 | clear cosAng 68 | 69 | % w is a nSpherePoints x nData matrix. Sum along the rows to calculate 70 | % the count value for this 71 | counts(idx) = sum(tmp,2); 72 | clear tmp 73 | end 74 | dispstat(''); 75 | 76 | 77 | 78 | 79 | end 80 | 81 | % calculate standard deviation (eq 13b) 82 | stdDev = sqrt(m*nData*(k/2-1)/(k^2)); 83 | 84 | % normalize so each MUD is 3 sigma from that expected for a uniform 85 | % distribution 86 | counts = counts/(3*stdDev); 87 | 88 | % reshape counts back to square matrix 89 | counts = reshape(counts,nSpherePoints,nSpherePoints); 90 | 91 | % Parse output 92 | Directions.parameter = stdDev; 93 | Directions.paramName = sprintf('\\sigma = %02.2f',stdDev); 94 | Directions.counts = counts; 95 | Directions.minCounts = min(counts(:)); 96 | Directions.maxCounts = max(counts(:)); 97 | 98 | 99 | end 100 | -------------------------------------------------------------------------------- /Contour/initcrystaldirections.m: -------------------------------------------------------------------------------- 1 | function CrystalDirections = initcrystaldirections(nDirections) 2 | % function to initialize CrystalDirection structure 3 | 4 | CrystalDirections(nDirections) = ... 5 | struct('name', [],... 6 | 'nData', [],... 7 | 'multiplicity', [],... 8 | 'unitVectors', [],... 9 | 'parameter', [],... 10 | 'paramName', [],... 11 | 'counts', [],... 12 | 'minCounts', [],... 13 | 'maxCounts', []); 14 | end -------------------------------------------------------------------------------- /Contour/kambcontour.m: -------------------------------------------------------------------------------- 1 | function CrystalDirections = kambcontour(CrystalDirections,LambertProj) 2 | 3 | 4 | % parse inputs 5 | gridVectors = [LambertProj.x(:), LambertProj.y(:), LambertProj.z(:)]; 6 | [nSpherePoints,~] = size(LambertProj.X); 7 | 8 | 9 | % Calculate size of counting circle (window parameter) 10 | nData = CrystalDirections.nData; 11 | m = CrystalDirections.multiplicity; 12 | theta = acos(1-9/(m*(nData+9))); 13 | 14 | %... for extremely large numbers of directions (say, over 150,000) this 15 | %vectorized version can overload ram and become extremely slow. Include a 16 | %contingency plan 17 | if nData*m < 150000 18 | % vectorized version (much faster) 19 | data = CrystalDirections.unitVectors; 20 | 21 | % Calculate the angle between the spherePoint and each of the data points 22 | %... vectorized version (doesn't use cross-product) 23 | cosAng = gridVectors*data'; 24 | clear gridVectors 25 | 26 | fprintf(1,'Vectorized angular distance calculation for %s \n',CrystalDirections.name); 27 | angDist = acos(abs(cosAng)); % absolute value ensures acute angle is always returned 28 | clear cosAng 29 | 30 | % count distances less than theta 31 | counts = sum(angDist<=theta,2); clear angDist 32 | 33 | else 34 | % large set of angles (e.g. m poles in quartz has 6xdata). Use loops as 35 | % matrices are likely much too large for RAM 36 | 37 | counts = zeros(size(gridVectors(:,1))); 38 | dispstat(sprintf('Calculating angular distances for %s: \t',CrystalDirections.name),'keepprev','keepthis','timestamp'); 39 | for i = 1:nSpherePoints 40 | dispstat(100*i/nSpherePoints); 41 | 42 | % operate on a subset of sphere points 43 | idx = (i-1)*nSpherePoints + 1:(i-1)*nSpherePoints + nSpherePoints; 44 | 45 | % calculate dot product for this subset 46 | gridV = gridVectors(idx,:); % vector of grid point 47 | cosAng = gridV*CrystalDirections.unitVectors'; % dot product 48 | cosAng = acos(abs(cosAng)); % get angular distance 49 | 50 | counts(idx) = sum(cosAng <= theta,2); % number inside counting circle 51 | 52 | end 53 | dispstat('done'); 54 | 55 | clear cosAng 56 | 57 | end 58 | 59 | % reshape counts back to square matrix 60 | counts = reshape(counts,nSpherePoints,nSpherePoints); 61 | 62 | 63 | % normalize counts by sigma (std deviation), assuming uniformly distributed 64 | % binomial trials 65 | areaFrac = 9/(nData+9); 66 | sigma = sqrt(nData*areaFrac*(1-areaFrac)); 67 | counts = counts/(3*sigma); 68 | 69 | 70 | % Parse output 71 | 72 | CrystalDirections.parameter = theta; 73 | CrystalDirections.paramName = sprintf('Window = %02.2f%c',theta,char(176)); 74 | CrystalDirections.counts = counts; 75 | CrystalDirections.minCounts = min(counts(:)); 76 | CrystalDirections.maxCounts = max(counts(:)); 77 | -------------------------------------------------------------------------------- /Contour/lowerhemisphere.m: -------------------------------------------------------------------------------- 1 | function [dataLower] = lowerhemisphere(data) 2 | % This function takes a set of unit vectors and converts them all to lower 3 | % hemisphere. Data is input (and output) as an Nx3 matrix 4 | 5 | x = data(:,1); 6 | y = data(:,2); 7 | z = data(:,3); 8 | 9 | [tr,pl] = cart2sph(x,y,z); 10 | [idx] = find(pl(:) > 0); 11 | pl(idx) = -pl(idx); 12 | tr(idx) = tr(idx) + pi; 13 | 14 | [x,y,z] = sph2cart(tr,pl,1); 15 | 16 | dataLower = [x(:), y(:), z(:)]; 17 | 18 | end 19 | -------------------------------------------------------------------------------- /Contour/makepolefigures.m: -------------------------------------------------------------------------------- 1 | function [hFig] = makepolefigures(CrystalDirections,mineral,SphereProj,hFig,ColorOpts) 2 | 3 | % Parse Values common to each axis (coordinate frame) 4 | X = SphereProj.X; 5 | Y = SphereProj.Y; 6 | R = SphereProj.R; % radius of circle in X and Y 7 | 8 | % Setup Figure Properties 9 | hFig.Units = 'centimeters'; 10 | hFig.Position = [0,0,19,10]; % 2 column figure width is 19 cm 11 | hFig.Name = 'Pole Figures'; 12 | movegui(hFig,'northwest'); 13 | fontSize = 18; 14 | 15 | % Calculate pole figure spacing for three pole figures + 1 infobox 16 | figBox = 19; 17 | nAxesHz = 3; % 4 horizontal subaxes 18 | subaxesSpacing = 0.25*(1/figBox); % 1/4 cm spacing between axes 19 | totalSpacing = (nAxesHz+1)*subaxesSpacing; % total spacing (normalized) 20 | subaxesWidth = (1-totalSpacing)/nAxesHz; 21 | 22 | colorRamp0 = ColorOpts.colorRamp0; 23 | nTics = ColorOpts.nTics; 24 | zeroValue = ColorOpts.centerVal; 25 | factor = ColorOpts.factor; 26 | 27 | % Now make pole figure plot 28 | switch mineral 29 | case 'olivine' 30 | 31 | %... create common colormap 32 | minCounts = min([CrystalDirections(:).minCounts]); 33 | 34 | [maxCounts,idx] = max([CrystalDirections(:).maxCounts]); 35 | 36 | 37 | 38 | %... modify counts for proper scaling 39 | mask = zeros(size(X)); 40 | mask(sqrt(X.^2 + Y.^2) >= R +0.025) = NaN; % mask values outside net 41 | mask(sqrt(X.^2 + Y.^2) < R +0.025) = 1; 42 | counts = CrystalDirections(idx).counts.*mask; 43 | counts = counts(~isnan(counts(:))); 44 | % [colorRamp1,tics] = cmapscale(log(counts+1e-4),colorRamp0,factor,zeroValue,nTics); 45 | [colorRamp1,tics] = cmapscale(counts,colorRamp0,factor,zeroValue,nTics); 46 | 47 | 48 | % Plot Stereograms (1 row only) 49 | topRow = 0; 50 | for idx = 1:3 51 | hSub(idx) = axes; 52 | leftPos = idx*subaxesSpacing + (idx-1)*subaxesWidth; 53 | hSub(idx).Position = [leftPos,topRow,subaxesWidth,1]; 54 | 55 | if exist('padarray','builtin') 56 | % use gcolor for slightly betterplotting 57 | h = gcolor(X,Y,CrystalDirections(idx).counts.*mask); shading flat 58 | else 59 | % use pcolor to plot 60 | h=pcolor(X,Y,mask.*CrystalDirections(idx).counts); shading interp 61 | end 62 | hold on 63 | contour(X,Y,CrystalDirections(idx).counts.*mask,[2,2],'Color',[0.5,0.5,0.5],'LineWidth',2); 64 | 65 | set(gca,'YDir','normal', 'Color', 'none'); 66 | set(h,'alphadata',~isnan(CrystalDirections(idx).counts.*mask)); 67 | colormap(colorRamp1); 68 | hold on 69 | polenet(R); 70 | axis equal off 71 | % hTitle = title(CrystalDirections(idx).name,'FontSize',fontSize); 72 | % hTitle.Position = [0,1.5,0]; 73 | hSub(idx).CLim = [minCounts,maxCounts]; 74 | end 75 | 76 | % Plot the InfoBox 77 | %... create invisible axes the full size of the figure (makes locating textbox easier) 78 | hAxis = axes('units','normalized','pos',[0 0 1 1],... 79 | 'visible','off','handlevisibility','off'); 80 | 81 | % Colorbar 82 | leftPos = 3*subaxesSpacing + 2*subaxesWidth + 0.6*subaxesWidth; 83 | colormap(hAxis,colorRamp0) 84 | hCbar = colorbar(hAxis); 85 | 86 | cbarWidth = 0.25*subaxesWidth; 87 | hCbar.Location = 'northoutside'; % makes colorbar hz 88 | hCbar.Position = [leftPos,0.15,cbarWidth,0.03]; 89 | hCbar.FontSize = 14; 90 | hCbar.Title.String = 'MUD'; 91 | hCbar.Title.Units = 'normalized'; 92 | hCbar.Title.Position = [0.5,-4,0]; 93 | 94 | set(hAxis,'CLim',[0,1]) 95 | hCbar.Ticks = tics(:,1); 96 | hCbar.TickLabels = sprintf('%3.0f\n',tics(:,2)); 97 | 98 | 99 | % Textbox 100 | leftPos = 3*subaxesSpacing + 2*subaxesWidth; 101 | nData = CrystalDirections(1).nData; 102 | theta = CrystalDirections(1).parameter; 103 | 104 | 105 | stringLimited = sprintf(['N = %i \nMax: %03.2f'],... 106 | nData,maxCounts); 107 | 108 | text(leftPos,0.15,stringLimited,'parent',hAxis,'FontSize',13) 109 | 110 | 111 | case 'quartz' 112 | hFig.Position = [0,0,19,16]; % 2 column figure width is 19 cm 113 | 114 | 115 | 116 | %... create common colormap 117 | minCounts = min([CrystalDirections(:).minCounts]); 118 | 119 | [maxCounts,idx] = max([CrystalDirections(:).maxCounts]); 120 | 121 | %... modify counts for proper scaling 122 | mask = zeros(size(X)); 123 | mask(sqrt(X.^2 + Y.^2) > sqrt(2)+0.025) = NaN; % mask values outside net 124 | mask(sqrt(X.^2 + Y.^2) < sqrt(2)+0.025) = 1; 125 | counts = CrystalDirections(idx).counts.*mask; 126 | counts = counts(~isnan(counts(:))); 127 | [colorRamp1,tics] = cmapscale(counts,colorRamp0,factor,zeroValue,nTics); 128 | 129 | 130 | 131 | % Plot Stereograms (TOP ROW) 132 | topRow = 0.25; 133 | for idx = 1:3 134 | hSub(idx) = axes; 135 | leftPos = idx*subaxesSpacing + (idx-1)*subaxesWidth; 136 | hSub(idx).Position = [leftPos,topRow,subaxesWidth,1]; 137 | pcolor(X,Y,mask.*CrystalDirections(idx).counts); shading interp 138 | colormap(colorRamp1); 139 | hold on 140 | contour(X,Y,mask.*CrystalDirections(idx).counts,[2,2],'Color',[0.5,0.5,0.5],'LineWidth',2); 141 | polenet(sqrt(2)); 142 | axis equal off 143 | hTitle = title(CrystalDirections(idx).name,'FontSize',fontSize); 144 | hTitle.Position = [0,1.5,0]; 145 | hSub(idx).CLim = [minCounts,maxCounts]; 146 | end 147 | 148 | % Plot Stereograms (Bottom ROW) 149 | for idx = 4:5 150 | bottomRow = -0.25; 151 | hSub(idx) = axes; 152 | leftPos = (idx-3)*subaxesSpacing + (idx-4)*subaxesWidth + 0*subaxesWidth; 153 | hSub(idx).Position = [leftPos,bottomRow,subaxesWidth,1]; 154 | % contourf(X,Y,mask.*CrystalDirections(idx).counts,contourLevels); 155 | pcolor(X,Y,mask.*CrystalDirections(idx).counts); shading interp 156 | colormap(colorRamp1); 157 | hold on 158 | contour(X,Y,mask.*CrystalDirections(idx).counts,[2,2],'Color',[0.5,0.5,0.5],'LineWidth',2); 159 | polenet(sqrt(2)); 160 | axis equal off 161 | hTitle = title(CrystalDirections(idx).name,'FontSize',fontSize); 162 | hTitle.Position = [0,1.5,0]; 163 | hSub(idx).CLim = [minCounts,maxCounts]; 164 | end 165 | % Plot the InfoBox 166 | %... create invisible axes the full size of the figure (makes locating textbox easier) 167 | hAxis = axes('units','normalized','pos',[0 0 1 1],... 168 | 'visible','off','handlevisibility','off'); 169 | 170 | %... colorbar 171 | leftPos = 4*subaxesSpacing + 2*subaxesWidth + 0*subaxesWidth; 172 | colormap(hAxis,colorRamp0) 173 | hCbar = colorbar(hAxis); 174 | 175 | cbarWidth = 0.4*subaxesWidth; 176 | hCbar.Location = 'northoutside'; % makes colorbar hz 177 | hCbar.Position = [leftPos,0.25,cbarWidth,0.03]; 178 | hCbar.FontSize = 14; 179 | hCbar.Title.String = 'MUD'; 180 | hCbar.Title.Units = 'normalized'; 181 | hCbar.Title.Position = [0.5,-2.5,0]; 182 | 183 | set(hAxis,'CLim',[0,1]) 184 | % hCbar.Limits = [0,1]; 185 | hCbar.Ticks = tics(:,1); 186 | hCbar.TickLabels = sprintf('%3.0f\n',tics(:,2)); 187 | 188 | 189 | 190 | 191 | % Textbox 192 | nData = CrystalDirections(1).nData; 193 | theta = CrystalDirections(1).parameter; 194 | thetam3 = CrystalDirections(3).parameter; 195 | 196 | stringFull = sprintf(['N = %i \nMethod: Kamb \nRSD=1/3 \nWindow = %04.2f%c \nEqual',... 197 | ' Area Projection \nLower Hemisphere'],... 198 | nData,theta*180/pi,char(176)); 199 | 200 | stringLimited = sprintf([' N = %i \n [c]: %s',... 201 | '\n: %s \n Max: %03.2f'],... 202 | nData,CrystalDirections(1).paramName,CrystalDirections(2).paramName,maxCounts); 203 | 204 | stringLimited = sprintf(' N = %i',... 205 | nData); 206 | 207 | 208 | text(leftPos,0.35,stringLimited,'parent',hAxis,'FontSize',13) 209 | 210 | 211 | otherwise 212 | error('contourpolefigures.m: Specify quartz or olivine for mineral'); 213 | 214 | end 215 | 216 | end -------------------------------------------------------------------------------- /Contour/rotationmatrix2crystaldirections.m: -------------------------------------------------------------------------------- 1 | function [CrystalDirections,nDirections] = rotationmatrix2crystaldirections(g,mineral) 2 | 3 | %% Check inputs 4 | validatestring(mineral,{'olivine','quartz'}); 5 | 6 | 7 | %% Calculation 8 | switch mineral 9 | case 'olivine' 10 | % Get [100], [010], and [001] directions 11 | nDirections = 3; 12 | CrystalDirections = initcrystaldirections(nDirections); 13 | 14 | 15 | CrystalDirections(1).name = '[100]'; 16 | CrystalDirections(1).nData = numel(g(:,1)); 17 | CrystalDirections(1).multiplicity= 1; 18 | CrystalDirections(1).unitVectors = [g(:,1),g(:,2),g(:,3)]; 19 | 20 | CrystalDirections(2).name = '[010]'; 21 | CrystalDirections(2).nData = numel(g(:,1)); 22 | CrystalDirections(2).multiplicity= 1; 23 | CrystalDirections(2).unitVectors = [g(:,4),g(:,5),g(:,6)]; 24 | 25 | CrystalDirections(3).name = '[001]'; 26 | CrystalDirections(3).nData = numel(g(:,1)); 27 | CrystalDirections(3).multiplicity= 1; 28 | CrystalDirections(3).unitVectors = [g(:,7),g(:,8),g(:,9)]; 29 | 30 | case 'quartz' 31 | % Plots c axes, axes, and poles to r and m and ? 32 | nDirections = 5; 33 | CrystalDirections = initcrystaldirections(nDirections); 34 | 35 | % parse orientation matrix 36 | g11 = g(:,1); % R(:,1) being g21 seems to work for Lloyd samples... 37 | g12 = g(:,2); 38 | g13 = g(:,3); 39 | 40 | g21 = g(:,4); 41 | g22 = g(:,5); 42 | g23 = g(:,6); 43 | 44 | g31 = g(:,7); 45 | g32 = g(:,8); 46 | g33 = g(:,9); 47 | 48 | % get c axes 49 | % c = [g31, g32, g33]; 50 | 51 | % get a axes by symmetry 52 | a = sqrt(3)/2; 53 | gp11 = -0.5*g11 + a*g21; 54 | gp21 = -0.5*g12 + a*g22; 55 | gp31 = -0.5*g13 + a*g23; 56 | 57 | gpp11= -0.5*g11 - a*g21; 58 | gpp21= -0.5*g12 - a*g22; 59 | gpp31= -0.5*g13 - a*g23; 60 | 61 | 62 | % get poles to m planes 63 | theta = [30, 90, 150, 210, 270, 330]*pi/180; % all m 64 | m = zeros([numel(g11),3,6]); 65 | for i = 1:numel(theta) 66 | cosTh = cos(theta(i)); 67 | sinTh = sin(theta(i)); 68 | m(:,1,i) = cosTh*g11 - sinTh*g21; 69 | m(:,2,i) = cosTh*g12 - sinTh*g22; 70 | m(:,3,i) = cosTh*g13 - sinTh*g23; 71 | end 72 | 73 | % get poles to r plane 74 | for i = 1:6 75 | % r(:,1,i) = 0.5*(m(:,1,i) + g31); 76 | % r(:,2,i) = 0.5*(m(:,2,i) + g32); 77 | % r(:,3,i) = 0.5*(m(:,3,i) + g33); 78 | 79 | x = 0.5*(m(:,1,i) + g31); 80 | y = 0.5*(m(:,2,i) + g32); 81 | z = 0.5*(m(:,3,i) + g33); 82 | 83 | %... normalize to unit vector 84 | length = sqrt(sum(x.^2 + y.^2 + z.^2,2)); 85 | r(:,1,i) = x./length; 86 | r(:,2,i) = y./length; 87 | r(:,3,i) = z./length; 88 | 89 | end 90 | 91 | % assign crystal axes 92 | CrystalDirections(1).name = 'c-axes'; 93 | CrystalDirections(1).nData = numel(g11); 94 | CrystalDirections(1).multiplicity= 1; 95 | CrystalDirections(1).unitVectors = [g31,g32,g33]; 96 | 97 | CrystalDirections(2).name = ' axes'; 98 | CrystalDirections(2).nData = numel(g11); 99 | CrystalDirections(2).multiplicity = 3; 100 | CrystalDirections(2).unitVectors(:,1) = [g11; gp11; gpp11]; 101 | CrystalDirections(2).unitVectors(:,2) = [g21; gp21; gpp21]; 102 | CrystalDirections(2).unitVectors(:,3) = [g31; gp31; gpp31]; 103 | 104 | CrystalDirections(3).name = 'poles to (m)'; % positive m only (1:3) 105 | CrystalDirections(3).nData = numel(g11); 106 | CrystalDirections(3).multiplicity = 3; 107 | CrystalDirections(3).unitVectors(:,1) = [m(:,1,4); m(:,1,5); m(:,1,6)]; 108 | CrystalDirections(3).unitVectors(:,2) = [m(:,2,4); m(:,2,5); m(:,2,6)]; 109 | CrystalDirections(3).unitVectors(:,3) = [m(:,3,4); m(:,3,5); m(:,3,6)]; 110 | 111 | CrystalDirections(4).name = 'poles to (z)'; 112 | CrystalDirections(4).nData = numel(g11); 113 | CrystalDirections(4).multiplicity = 3; 114 | CrystalDirections(4).unitVectors(:,1) = [r(:,1,1); r(:,1,3); r(:,1,5)]; 115 | CrystalDirections(4).unitVectors(:,2) = [r(:,2,1); r(:,2,3); r(:,2,5)]; 116 | CrystalDirections(4).unitVectors(:,3) = [r(:,3,1); r(:,3,3); r(:,3,5)]; 117 | 118 | CrystalDirections(5).name = 'poles to (r)'; 119 | CrystalDirections(5).nData = numel(g11); 120 | CrystalDirections(5).multiplicity = 3; 121 | CrystalDirections(5).unitVectors(:,1) = [r(:,1,2); r(:,1,4); r(:,1,6)]; 122 | CrystalDirections(5).unitVectors(:,2) = [r(:,2,2); r(:,2,4); r(:,2,6)]; 123 | CrystalDirections(5).unitVectors(:,3) = [r(:,3,2); r(:,3,4); r(:,3,6)]; 124 | 125 | end 126 | end 127 | 128 | -------------------------------------------------------------------------------- /Contour/rotationmatrix2quartzdirections.m: -------------------------------------------------------------------------------- 1 | function [CrystalDirections,nDirections] = rotationmatrix2quartzdirections(R) 2 | % this function converts euler angles into crystal directions appropriate 3 | % for quartz 4 | 5 | % Plots c axes, axes, and poles to r and m and ? 6 | nDirections = 5; 7 | 8 | % parse orientation matrix 9 | g11 = R(:,1); % R(:,1) being g21 seems to work for Lloyd samples... 10 | g12 = R(:,2); 11 | g13 = R(:,3); 12 | 13 | g21 = R(:,4); 14 | g22 = R(:,5); 15 | g23 = R(:,6); 16 | 17 | g31 = R(:,7); 18 | g32 = R(:,8); 19 | g33 = R(:,9); 20 | 21 | % get c axes 22 | % c = [g31, g32, g33]; 23 | 24 | % get a axes by symmetry 25 | a = sqrt(3)/2; 26 | gp11 = -0.5*g11 + a*g21; 27 | gp21 = -0.5*g12 + a*g22; 28 | gp31 = -0.5*g13 + a*g23; 29 | 30 | gpp11= -0.5*g11 - a*g21; 31 | gpp21= -0.5*g12 - a*g22; 32 | gpp31= -0.5*g13 - a*g23; 33 | 34 | 35 | % get poles to m planes 36 | theta = [30, 90, 150, 210, 270, 330]*pi/180; % all m 37 | m = zeros([numel(g11),3,6]); 38 | for i = 1:numel(theta) 39 | cosTh = cos(theta(i)); 40 | sinTh = sin(theta(i)); 41 | m(:,1,i) = cosTh*g11 - sinTh*g21; 42 | m(:,2,i) = cosTh*g12 - sinTh*g22; 43 | m(:,3,i) = cosTh*g13 - sinTh*g23; 44 | end 45 | 46 | % get poles to r plane 47 | for i = 1:6 48 | % r(:,1,i) = 0.5*(m(:,1,i) + g31); 49 | % r(:,2,i) = 0.5*(m(:,2,i) + g32); 50 | % r(:,3,i) = 0.5*(m(:,3,i) + g33); 51 | 52 | x = 0.5*(m(:,1,i) + g31); 53 | y = 0.5*(m(:,2,i) + g32); 54 | z = 0.5*(m(:,3,i) + g33); 55 | 56 | %... normalize to unit vector 57 | length = sqrt(sum(x.^2 + y.^2 + z.^2,2)); 58 | r(:,1,i) = x./length; 59 | r(:,2,i) = y./length; 60 | r(:,3,i) = z./length; 61 | 62 | end 63 | 64 | % assign crystal axes 65 | CrystalDirections{1}.name = 'c-axes'; 66 | CrystalDirections{1}.nData = numel(g11); 67 | CrystalDirections{1}.multiplicity= 1; 68 | CrystalDirections{1}.unitVectors = [g31,g32,g33]; 69 | 70 | CrystalDirections{2}.name = ' axes'; 71 | CrystalDirections{2}.nData = numel(g11); 72 | CrystalDirections{2}.multiplicity = 3; 73 | CrystalDirections{2}.unitVectors(:,1) = [g11; gp11; gpp11]; 74 | CrystalDirections{2}.unitVectors(:,2) = [g21; gp21; gpp21]; 75 | CrystalDirections{2}.unitVectors(:,3) = [g31; gp31; gpp31]; 76 | 77 | CrystalDirections{3}.name = 'poles to {m}'; % positive m only (1:3) 78 | CrystalDirections{3}.nData = numel(g11); 79 | CrystalDirections{3}.multiplicity = 3; 80 | CrystalDirections{3}.unitVectors(:,1) = [m(:,1,4); m(:,1,5); m(:,1,6)]; 81 | CrystalDirections{3}.unitVectors(:,2) = [m(:,2,4); m(:,2,5); m(:,2,6)]; 82 | CrystalDirections{3}.unitVectors(:,3) = [m(:,3,4); m(:,3,5); m(:,3,6)]; 83 | 84 | CrystalDirections{4}.name = 'poles to {z}'; 85 | CrystalDirections{4}.nData = numel(g11); 86 | CrystalDirections{4}.multiplicity = 3; 87 | CrystalDirections{4}.unitVectors(:,1) = [r(:,1,1); r(:,1,3); r(:,1,5)]; 88 | CrystalDirections{4}.unitVectors(:,2) = [r(:,2,1); r(:,2,3); r(:,2,5)]; 89 | CrystalDirections{4}.unitVectors(:,3) = [r(:,3,1); r(:,3,3); r(:,3,5)]; 90 | 91 | CrystalDirections{5}.name = 'poles to {r}'; 92 | CrystalDirections{5}.nData = numel(g11); 93 | CrystalDirections{5}.multiplicity = 3; 94 | CrystalDirections{5}.unitVectors(:,1) = [r(:,1,2); r(:,1,4); r(:,1,6)]; 95 | CrystalDirections{5}.unitVectors(:,2) = [r(:,2,2); r(:,2,4); r(:,2,6)]; 96 | CrystalDirections{5}.unitVectors(:,3) = [r(:,3,2); r(:,3,4); r(:,3,6)]; 97 | 98 | 99 | %... Bunge convention (ZXZ), passive rotation 100 | % R(:,1)= c1.*c3 - c2.*s1.*s3; %R11 101 | % R(:,2)= c3.*s1 + c1.*c2.*s3; %R12 102 | % R(:,3)= s2.*s3; %R13 103 | % 104 | % R(:,4)=-c1.*s3 - c2.*c3.*s1; %R21 105 | % R(:,5)= c1.*c2.*c3 - s1.*s3; %R22 106 | % R(:,6)= c3.*s2; %R23 107 | % 108 | % R(:,7)= s1.*s2; %R31 109 | % R(:,8)=-c1.*s2; %R32 110 | % R(:,9)= c2; %R33 111 | 112 | 113 | end -------------------------------------------------------------------------------- /Contour/test-quartz.txt: -------------------------------------------------------------------------------- 1 | phi1 Phi phi2 phase bands bc bs error mad x y phaseId 2 | 0 -90 0 3 | 0 -90 0 4 | 0 -90 0 5 | 0 -90 0 6 | 0 -90 0 7 | 0 -90 0 8 | 0 -90 0 9 | 0 -90 0 10 | 0 -90 0 11 | 0 -90 0 12 | 0 -90 0 13 | 0 -90 0 14 | 0 -90 0 15 | 0 -90 0 16 | 0 -90 0 17 | 0 -90 0 18 | 0 -90 0 19 | 0 -90 0 20 | 0 -90 0 21 | 0 -90 0 22 | 0 -90 0 23 | 0 -90 0 24 | 0 -90 0 25 | 0 -90 0 26 | 0 -90 0 27 | 0 -90 0 28 | 0 -90 0 29 | 0 -90 0 30 | 0 -90 0 31 | 0 -90 0 32 | 0 -90 0 33 | 0 -90 0 34 | 0 -90 0 35 | 0 -90 0 36 | 0 -90 0 37 | 0 -90 0 38 | 0 -90 0 39 | 0 -90 0 40 | 0 -90 0 41 | 0 -90 0 42 | 0 -90 0 43 | 0 -90 0 44 | 45 | -------------------------------------------------------------------------------- /Contour/testcontourstereogram.m: -------------------------------------------------------------------------------- 1 | function [] = testcontourstereogram() 2 | commandwindow 3 | keyboard 4 | %% Simple test 5 | close all; clear all; clc 6 | eulerAngles = [35,16,280; 173,163,023; 267,016,163; 000,173,123]*pi/180; 7 | mineral = 'olivine'; 8 | contourpolefigures(eulerAngles,mineral,'Gaussian',1,'lower',51) 9 | %% Test Olivine 10 | close all; clear all; clc 11 | % Read in euler angle file 12 | fileName = 'drex_simpleShear.txt'; 13 | fid = fopen(fileName); 14 | angles = textscan(fid,'%f %f %f %*[^\r\n]','HeaderLines',1); 15 | eulerAngles = [angles{1},angles{2},angles{3}]*pi/180; 16 | clear angles; 17 | 18 | mineral = 'olivine'; 19 | method = 'Gaussian'; 20 | ColorOpts.colorRamp0 = coolwarm(256); 21 | ColorOpts.nTics = 3; 22 | ColorOpts.centerVal = 1; 23 | ColorOpts.factor = 0.5; 24 | 25 | hFig = contourpolefigures(eulerAngles,mineral,method,[],[],[],ColorOpts); 26 | 27 | 28 | %% Test Quartz 29 | clc 30 | close all 31 | % fileName = 'test-quartz.txt'; 32 | % fileName = 'MT-07-76.txt'; 33 | % fileName = 'MT1a-out.txt'; 34 | fileName = 'MT6-out.txt'; 35 | fid = fopen(fileName); 36 | angles = textscan(fid,'%f %f %f %*[^\r\n]','HeaderLines',1); 37 | eulerAngles = [angles{1},angles{2},angles{3}]*pi/180; 38 | clear angles 39 | 40 | 41 | mineral = 'quartz'; 42 | method = 'Gaussian'; 43 | ColorOpts.colorRamp0 = coolwarm(256); 44 | ColorOpts.nTics = 3; 45 | ColorOpts.centerVal = 1; 46 | ColorOpts.factor = 0.5; 47 | 48 | hFig = contourpolefigures(eulerAngles,mineral,method,[],[],151,ColorOpts); 49 | 50 | 51 | end 52 | 53 | -------------------------------------------------------------------------------- /Images/_Figure_SyntheticOlivine.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cthissen/Drex-MATLAB/39da9a38b1783c46fe4f2ac49e1c059e3c313b96/Images/_Figure_SyntheticOlivine.png -------------------------------------------------------------------------------- /Images/_Figure_SyntheticOlivineFlows-01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cthissen/Drex-MATLAB/39da9a38b1783c46fe4f2ac49e1c059e3c313b96/Images/_Figure_SyntheticOlivineFlows-01.png -------------------------------------------------------------------------------- /License.md: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Christopher Thissen 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Drex # 2 | 3 | What is it? 4 | ----------------- 5 | Drex simulates the rotation of crystal orientations and development of preferred orientations in a deforming olivine aggregate. 6 | 7 | 8 | Motivation 9 | ------------------ 10 | The development of crystal preferred orientations in olivine (and other minerals) has important implications for understanding the dynamics of the earth's interior. Various computer models have been developed to simulate the rotation of crystal orientations in olivine aggregrates, but they have proven difficult to use. This is a version of the popular Drex model, implemented with user-friendliness in mind. 11 | 12 | 13 | Requirements 14 | ------------------ 15 | Drex requires Matlab 2014 or later. No additional toolboxes are required to run the program. 16 | 17 | 18 | Installation 19 | ------------------ 20 | No installation is necessary. 21 | 22 | 23 | Usage 24 | ------------------ 25 | The code does not require input arguments and can be run by calling the program in the MATLAB command window or pushing the green "Run" button. User-adjustable parameters can be found in Drex.m. See the Drex.m file for additional information. 26 | 27 | 28 | The Latest Version 29 | ------------------ 30 | Details of the latest version can be found on the github project page under 31 | server project page under https://github.com/cthissen/Drex-MATLAB 32 | 33 | 34 | Contributors 35 | ------------------ 36 | Christopher Thissen, Yale University. christopher.thissen@yale.edu 37 | with contributions from Mark Brandon, Yale University 38 | 39 | 40 | Feedback 41 | ------------------ 42 | Your comments are welcome! If you find any bugs or have feature requests report them to 43 | Christopher Thissen, christopher.thissen@yale.edu. 44 | 45 | Issues can also be reported online: https://github.com/cthissen/Drex-MATLAB/issues 46 | 47 | 48 | 49 | License 50 | ------------------ 51 | See License file. 52 | 53 | -------------------------------------------------------------------------------- /colormaps/algae.m: -------------------------------------------------------------------------------- 1 | function map = algae(m) 2 | %algae color map 3 | % algae(M) returns an M-by-3 matrix containing a colormap with 'algae' 4 | % colors. 5 | % algae, by itself, is the same length as the current colormap. 6 | % 7 | % For example, to reset the colormap of the current figure: 8 | % 9 | % colormap(coolwarm) 10 | % 11 | % This colormap is a diverging-qualitative colormap that scales from blue to green to yellow to red 12 | % http://soliton.vm.bytemark.co.uk/pub/cpt-city/ 13 | % The code structure follows coolwarm.m by Mark Brandon (Yale). 14 | 15 | % Christopher Thissen 16 | % Yale University 17 | % Time-stamp: 18 | 19 | %% Check inputs 20 | narginchk(0,1); 21 | 22 | if nargin == 1 23 | validateattributes(m,{'numeric'},{'numel',1}); 24 | end 25 | 26 | %% Begin Function 27 | 28 | if nargin < 1, m = size(get(gcf,'colormap'),1); end 29 | c = ... 30 | [ 80.0000 0 80.0000 31 | 78.4314 0 82.7451 32 | 76.8627 0 85.4902 33 | 75.2941 0 88.2353 34 | 73.7255 0 90.9804 35 | 72.1569 0 93.7255 36 | 70.5882 0 96.4706 37 | 69.0196 0 99.2157 38 | 67.4510 0 101.9608 39 | 65.8824 0 104.7059 40 | 64.3137 0 107.4510 41 | 62.7451 0 110.1961 42 | 61.1765 0 112.9412 43 | 59.6078 0 115.6863 44 | 58.0392 0 118.4314 45 | 56.4706 0 121.1765 46 | 54.9020 0 123.9216 47 | 53.3333 0 126.6667 48 | 51.7647 0 129.4118 49 | 50.1961 0 132.1569 50 | 48.6275 0 134.9020 51 | 47.0588 0 137.6471 52 | 45.4902 0 140.3922 53 | 43.9216 0 143.1373 54 | 42.3529 0 145.8824 55 | 40.7843 0 148.6275 56 | 39.2157 0 151.3725 57 | 37.6471 0 154.1176 58 | 36.0784 0 156.8627 59 | 34.5098 0 159.6078 60 | 32.9412 0 162.3529 61 | 31.3725 0 165.0980 62 | 29.8039 0 167.8431 63 | 28.2353 0 170.5882 64 | 26.6667 0 173.3333 65 | 25.0980 0 176.0784 66 | 23.5294 0 178.8235 67 | 21.9608 0 181.5686 68 | 20.3922 0 184.3137 69 | 18.8235 0 187.0588 70 | 17.2549 0 189.8039 71 | 15.6863 0 192.5490 72 | 14.1176 0 195.2941 73 | 12.5490 0 198.0392 74 | 10.9804 0 200.7843 75 | 9.4118 0 203.5294 76 | 7.8431 0 206.2745 77 | 6.2745 0 209.0196 78 | 4.7059 0 211.7647 79 | 3.1373 0 214.5098 80 | 1.5686 0 217.2549 81 | 0 0 220.0000 82 | 0 2.5490 215.6863 83 | 0 5.0980 211.3725 84 | 0 7.6471 207.0588 85 | 0 10.1961 202.7451 86 | 0 12.7451 198.4314 87 | 0 15.2941 194.1176 88 | 0 17.8431 189.8039 89 | 0 20.3922 185.4902 90 | 0 22.9412 181.1765 91 | 0 25.4902 176.8627 92 | 0 28.0392 172.5490 93 | 0 30.5882 168.2353 94 | 0 33.1373 163.9216 95 | 0 35.6863 159.6078 96 | 0 38.2353 155.2941 97 | 0 40.7843 150.9804 98 | 0 43.3333 146.6667 99 | 0 45.8824 142.3529 100 | 0 48.4314 138.0392 101 | 0 50.9804 133.7255 102 | 0 53.5294 129.4118 103 | 0 56.0784 125.0980 104 | 0 58.6275 120.7843 105 | 0 61.1765 116.4706 106 | 0 63.7255 112.1569 107 | 0 66.2745 107.8431 108 | 0 68.8235 103.5294 109 | 0 71.3725 99.2157 110 | 0 73.9216 94.9020 111 | 0 76.4706 90.5882 112 | 0 79.0196 86.2745 113 | 0 81.5686 81.9608 114 | 0 84.1176 77.6471 115 | 0 86.6667 73.3333 116 | 0 89.2157 69.0196 117 | 0 91.7647 64.7059 118 | 0 94.3137 60.3922 119 | 0 96.8627 56.0784 120 | 0 99.4118 51.7647 121 | 0 101.9608 47.4510 122 | 0 104.5098 43.1373 123 | 0 107.0588 38.8235 124 | 0 109.6078 34.5098 125 | 0 112.1569 30.1961 126 | 0 114.7059 25.8824 127 | 0 117.2549 21.5686 128 | 0 119.8039 17.2549 129 | 0 122.3529 12.9412 130 | 0 124.9020 8.6275 131 | 0 127.4510 4.3137 132 | 0 130.0000 0 133 | 5.0196 132.4706 0.3922 134 | 10.0392 134.9412 0.7843 135 | 15.0588 137.4118 1.1765 136 | 20.0784 139.8824 1.5686 137 | 25.0980 142.3529 1.9608 138 | 30.1176 144.8235 2.3529 139 | 35.1373 147.2941 2.7451 140 | 40.1569 149.7647 3.1373 141 | 45.1765 152.2353 3.5294 142 | 50.1961 154.7059 3.9216 143 | 55.2157 157.1765 4.3137 144 | 60.2353 159.6471 4.7059 145 | 65.2549 162.1176 5.0980 146 | 70.2745 164.5882 5.4902 147 | 75.2941 167.0588 5.8824 148 | 80.3137 169.5294 6.2745 149 | 85.3333 172.0000 6.6667 150 | 90.3529 174.4706 7.0588 151 | 95.3725 176.9412 7.4510 152 | 100.3922 179.4118 7.8431 153 | 105.4118 181.8824 8.2353 154 | 110.4314 184.3529 8.6275 155 | 115.4510 186.8235 9.0196 156 | 120.4706 189.2941 9.4118 157 | 125.4902 191.7647 9.8039 158 | 130.5098 194.2353 10.1961 159 | 135.5294 196.7059 10.5882 160 | 140.5490 199.1765 10.9804 161 | 145.5686 201.6471 11.3725 162 | 150.5882 204.1176 11.7647 163 | 155.6078 206.5882 12.1569 164 | 160.6275 209.0588 12.5490 165 | 165.6471 211.5294 12.9412 166 | 170.6667 214.0000 13.3333 167 | 175.6863 216.4706 13.7255 168 | 180.7059 218.9412 14.1176 169 | 185.7255 221.4118 14.5098 170 | 190.7451 223.8824 14.9020 171 | 195.7647 226.3529 15.2941 172 | 200.7843 228.8235 15.6863 173 | 205.8039 231.2941 16.0784 174 | 210.8235 233.7647 16.4706 175 | 215.8431 236.2353 16.8627 176 | 220.8627 238.7059 17.2549 177 | 225.8824 241.1765 17.6471 178 | 230.9020 243.6471 18.0392 179 | 235.9216 246.1176 18.4314 180 | 240.9412 248.5882 18.8235 181 | 245.9608 251.0588 19.2157 182 | 250.9804 253.5294 19.6078 183 | 256.0000 256.0000 20.0000 184 | 256.0000 253.4902 19.8039 185 | 256.0000 250.9804 19.6078 186 | 256.0000 248.4706 19.4118 187 | 256.0000 245.9608 19.2157 188 | 256.0000 243.4510 19.0196 189 | 256.0000 240.9412 18.8235 190 | 256.0000 238.4314 18.6275 191 | 256.0000 235.9216 18.4314 192 | 256.0000 233.4118 18.2353 193 | 256.0000 230.9020 18.0392 194 | 256.0000 228.3922 17.8431 195 | 256.0000 225.8824 17.6471 196 | 256.0000 223.3725 17.4510 197 | 256.0000 220.8627 17.2549 198 | 256.0000 218.3529 17.0588 199 | 256.0000 215.8431 16.8627 200 | 256.0000 213.3333 16.6667 201 | 256.0000 210.8235 16.4706 202 | 256.0000 208.3137 16.2745 203 | 256.0000 205.8039 16.0784 204 | 256.0000 203.2941 15.8824 205 | 256.0000 200.7843 15.6863 206 | 256.0000 198.2745 15.4902 207 | 256.0000 195.7647 15.2941 208 | 256.0000 193.2549 15.0980 209 | 256.0000 190.7451 14.9020 210 | 256.0000 188.2353 14.7059 211 | 256.0000 185.7255 14.5098 212 | 256.0000 183.2157 14.3137 213 | 256.0000 180.7059 14.1176 214 | 256.0000 178.1961 13.9216 215 | 256.0000 175.6863 13.7255 216 | 256.0000 173.1765 13.5294 217 | 256.0000 170.6667 13.3333 218 | 256.0000 168.1569 13.1373 219 | 256.0000 165.6471 12.9412 220 | 256.0000 163.1373 12.7451 221 | 256.0000 160.6275 12.5490 222 | 256.0000 158.1176 12.3529 223 | 256.0000 155.6078 12.1569 224 | 256.0000 153.0980 11.9608 225 | 256.0000 150.5882 11.7647 226 | 256.0000 148.0784 11.5686 227 | 256.0000 145.5686 11.3725 228 | 256.0000 143.0588 11.1765 229 | 256.0000 140.5490 10.9804 230 | 256.0000 138.0392 10.7843 231 | 256.0000 135.5294 10.5882 232 | 256.0000 133.0196 10.3922 233 | 256.0000 130.5098 10.1961 234 | 256.0000 128.0000 10.0000 235 | 256.0000 125.4902 9.8039 236 | 256.0000 122.9804 9.6078 237 | 256.0000 120.4706 9.4118 238 | 256.0000 117.9608 9.2157 239 | 256.0000 115.4510 9.0196 240 | 256.0000 112.9412 8.8235 241 | 256.0000 110.4314 8.6275 242 | 256.0000 107.9216 8.4314 243 | 256.0000 105.4118 8.2353 244 | 256.0000 102.9020 8.0392 245 | 256.0000 100.3922 7.8431 246 | 256.0000 97.8824 7.6471 247 | 256.0000 95.3725 7.4510 248 | 256.0000 92.8627 7.2549 249 | 256.0000 90.3529 7.0588 250 | 256.0000 87.8431 6.8627 251 | 256.0000 85.3333 6.6667 252 | 256.0000 82.8235 6.4706 253 | 256.0000 80.3137 6.2745 254 | 256.0000 77.8039 6.0784 255 | 256.0000 75.2941 5.8824 256 | 256.0000 72.7843 5.6863 257 | 256.0000 70.2745 5.4902 258 | 256.0000 67.7647 5.2941 259 | 256.0000 65.2549 5.0980 260 | 256.0000 62.7451 4.9020 261 | 256.0000 60.2353 4.7059 262 | 256.0000 57.7255 4.5098 263 | 256.0000 55.2157 4.3137 264 | 256.0000 52.7059 4.1176 265 | 256.0000 50.1961 3.9216 266 | 256.0000 47.6863 3.7255 267 | 256.0000 45.1765 3.5294 268 | 256.0000 42.6667 3.3333 269 | 256.0000 40.1569 3.1373 270 | 256.0000 37.6471 2.9412 271 | 256.0000 35.1373 2.7451 272 | 256.0000 32.6275 2.5490 273 | 249.7647 30.1176 2.3529 274 | 241.4510 27.6078 2.1569 275 | 233.1373 25.0980 1.9608 276 | 224.8235 22.5882 1.7647 277 | 216.5098 20.0784 1.5686 278 | 208.1961 17.5686 1.3725 279 | 199.8824 15.0588 1.1765 280 | 191.5686 12.5490 0.9804 281 | 183.2549 10.0392 0.7843 282 | 174.9412 7.5294 0.5882 283 | 166.6275 5.0196 0.3922 284 | 158.3137 2.5098 0.1961 285 | 150.0000 0 0]; 286 | 287 | %... Interpolate get requested size for color table 288 | pp=1:(m-1)/(size(c,1)-1):m; 289 | r=interp1(pp,c(:,1),1:m); 290 | g=interp1(pp,c(:,2),1:m); 291 | b=interp1(pp,c(:,3),1:m); 292 | %... Normalize to range [0,1], and divide again by maximum value 293 | % to correct for round-off errors associated with the interpolation. 294 | map=[r' g' b']/256; 295 | map = map/max(map(:)); 296 | 297 | %% LINT - Generate c matrix 298 | % % interpolate to linear spacing (used to generate c matrix above) 299 | % x = [0,0.2,0.4,0.6,0.95,1.0]; 300 | % cOrig = ... 301 | % [80 0 80; 302 | % 0 0 220; 303 | % 0 130 0; 304 | % 256 256 20; 305 | % 256 32 2.5; 306 | % 150 0 0]; 307 | % 308 | % xI = linspace(0,1,256); 309 | % rI = interp1(x,cOrig(:,1),xI)'; 310 | % gI = interp1(x,cOrig(:,2),xI)'; 311 | % bI = interp1(x,cOrig(:,3),xI)'; 312 | % c = [rI,gI,bI] 313 | 314 | %% LINT - original .cpt file 315 | % # bds_highcontrast AKA algae 316 | % # https://urldefense.proofpoint.com/v2/url?u=http-3A__pydoc.net_Python_yt_3.1_yt.visualization.color-5Fmaps_&d=AwICAg&c=-dg2m7zWuuDZ0MUcV7Sdqw&r=pSbXBPH3UferyZhMLabHraXEETVqVsrZu68QmtCL2Xs&m=C7hGIvYG0g5F2Z0MtFbnlafyevIys-jKMYTeUZwPrlo&s=-cUX24w0QBlA9k8dDNSc8TbrLvHFIcPtyLVF20B9zJk&e= 317 | % # The format is as follows: 318 | % # First number is the number at which we are defining a color breakpoint 319 | % # Second number is the (0..1) number to interpolate to when coming *from below* 320 | % # Third number is the (0..1) number to interpolate to when coming *from above* 321 | % 322 | % # Next up is boilerplate -- the name, the colormap dict we just made, and the 323 | % # number of segments we want. This is probably fine as is. 324 | % 325 | % cdict = {'red': ((0.0, 80/256., 80/256.), 326 | % (0.2, 0.0, 0.0), 327 | % (0.4, 0.0, 0.0), 328 | % (0.6, 256/256., 256/256.), 329 | % (0.95, 256/256., 256/256.), 330 | % (1.0, 150/256., 150/256.)), 331 | % 'green': ((0.0, 0/256., 0/256.), 332 | % (0.2, 0/256., 0/256.), 333 | % (0.4, 130/256., 130/256.), 334 | % (0.6, 256/256., 256/256.), 335 | % (1.0, 0.0, 0.0)), 336 | % 'blue': ((0.0, 80/256., 80/256.), 337 | % (0.2, 220/256., 220/256.), 338 | % (0.4, 0.0, 0.0), 339 | % (0.6, 20/256., 20/256.), 340 | % (1.0, 0.0, 0.0))} 341 | % 342 | % add_cmap('bds_highcontrast', cdict) 343 | % add_cmap('algae', cdict) 344 | 345 | 346 | 347 | -------------------------------------------------------------------------------- /colormaps/coolwarm.m: -------------------------------------------------------------------------------- 1 | function map = coolwarm(m) 2 | %COOLWARM cool-warm color map 3 | % COOLWARM(M) returns an M-by-3 matrix containing a colormap with cool-to-warm 4 | % colors, as commonly used in Paraview. 5 | % COOLWARM, by itself, is the same length as the current colormap. 6 | % 7 | % For example, to reset the colormap of the current figure: 8 | % 9 | % colormap(coolwarm) 10 | % 11 | % Colormap is based on the colors used by the freeware program Paraview. 12 | % The color table used here is CoolWarmUChar33.csv, from 13 | % http://www.sandia.gov/~kmorel/documents/ColorMaps/ 14 | % Reference: Moreland, Kenneth, 2009, Diverging Color Maps for Scientific 15 | % Visualization, in Proceedings of the 5th International Symposium on 16 | % Visual Computing. 17 | % The Matlab code is after haxby.m by Kelsey Jordahl, Marymount Manhattan 18 | % College. 19 | % 20 | % See also HSV, GRAY, PINK, COOL, BONE, COPPER, FLAG, HOT 21 | % COLORMAP, RGBPLOT, HAXBY. 22 | 23 | % Mark Brandon 24 | % Yale University 25 | % Time-stamp: 26 | 27 | %% Check inputs 28 | narginchk(0,1); 29 | 30 | if nargin == 1 31 | validateattributes(m,{'numeric'},{'numel',1}); 32 | end 33 | 34 | %% Begin Function 35 | if nargin < 1, m = size(get(gcf,'colormap'),1); end 36 | c=[59 76 192; 37 | 60 78 194; 38 | 61 80 195; 39 | 62 81 197; 40 | 63 83 198; 41 | 64 85 200; 42 | 66 87 201; 43 | 67 88 203; 44 | 68 90 204; 45 | 69 92 206; 46 | 70 93 207; 47 | 71 95 209; 48 | 73 97 210; 49 | 74 99 211; 50 | 75 100 213; 51 | 76 102 214; 52 | 77 104 215; 53 | 79 105 217; 54 | 80 107 218; 55 | 81 109 219; 56 | 82 110 221; 57 | 84 112 222; 58 | 85 114 223; 59 | 86 115 224; 60 | 87 117 225; 61 | 89 119 226; 62 | 90 120 228; 63 | 91 122 229; 64 | 93 123 230; 65 | 94 125 231; 66 | 95 127 232; 67 | 96 128 233; 68 | 98 130 234; 69 | 99 131 235; 70 | 100 133 236; 71 | 102 135 237; 72 | 103 136 238; 73 | 104 138 239; 74 | 106 139 239; 75 | 107 141 240; 76 | 108 142 241; 77 | 110 144 242; 78 | 111 145 243; 79 | 112 147 243; 80 | 114 148 244; 81 | 115 150 245; 82 | 116 151 246; 83 | 118 153 246; 84 | 119 154 247; 85 | 120 156 247; 86 | 122 157 248; 87 | 123 158 249; 88 | 124 160 249; 89 | 126 161 250; 90 | 127 163 250; 91 | 129 164 251; 92 | 130 165 251; 93 | 131 167 252; 94 | 133 168 252; 95 | 134 169 252; 96 | 135 171 253; 97 | 137 172 253; 98 | 138 173 253; 99 | 140 174 254; 100 | 141 176 254; 101 | 142 177 254; 102 | 144 178 254; 103 | 145 179 254; 104 | 147 181 255; 105 | 148 182 255; 106 | 149 183 255; 107 | 151 184 255; 108 | 152 185 255; 109 | 153 186 255; 110 | 155 187 255; 111 | 156 188 255; 112 | 158 190 255; 113 | 159 191 255; 114 | 160 192 255; 115 | 162 193 255; 116 | 163 194 255; 117 | 164 195 254; 118 | 166 196 254; 119 | 167 197 254; 120 | 168 198 254; 121 | 170 199 253; 122 | 171 199 253; 123 | 172 200 253; 124 | 174 201 253; 125 | 175 202 252; 126 | 176 203 252; 127 | 178 204 251; 128 | 179 205 251; 129 | 180 205 251; 130 | 182 206 250; 131 | 183 207 250; 132 | 184 208 249; 133 | 185 208 248; 134 | 187 209 248; 135 | 188 210 247; 136 | 189 210 247; 137 | 190 211 246; 138 | 192 212 245; 139 | 193 212 245; 140 | 194 213 244; 141 | 195 213 243; 142 | 197 214 243; 143 | 198 214 242; 144 | 199 215 241; 145 | 200 215 240; 146 | 201 216 239; 147 | 203 216 238; 148 | 204 217 238; 149 | 205 217 237; 150 | 206 217 236; 151 | 207 218 235; 152 | 208 218 234; 153 | 209 219 233; 154 | 210 219 232; 155 | 211 219 231; 156 | 213 219 230; 157 | 214 220 229; 158 | 215 220 228; 159 | 216 220 227; 160 | 217 220 225; 161 | 218 220 224; 162 | 219 220 223; 163 | 220 221 222; 164 | 221 221 221; 165 | 222 220 219; 166 | 223 220 218; 167 | 224 219 216; 168 | 225 219 215; 169 | 226 218 214; 170 | 227 218 212; 171 | 228 217 211; 172 | 229 216 209; 173 | 230 216 208; 174 | 231 215 206; 175 | 232 215 205; 176 | 232 214 203; 177 | 233 213 202; 178 | 234 212 200; 179 | 235 212 199; 180 | 236 211 197; 181 | 236 210 196; 182 | 237 209 194; 183 | 238 209 193; 184 | 238 208 191; 185 | 239 207 190; 186 | 240 206 188; 187 | 240 205 187; 188 | 241 204 185; 189 | 241 203 184; 190 | 242 202 182; 191 | 242 201 181; 192 | 243 200 179; 193 | 243 199 178; 194 | 244 198 176; 195 | 244 197 174; 196 | 245 196 173; 197 | 245 195 171; 198 | 245 194 170; 199 | 245 193 168; 200 | 246 192 167; 201 | 246 191 165; 202 | 246 190 163; 203 | 246 188 162; 204 | 247 187 160; 205 | 247 186 159; 206 | 247 185 157; 207 | 247 184 156; 208 | 247 182 154; 209 | 247 181 152; 210 | 247 180 151; 211 | 247 178 149; 212 | 247 177 148; 213 | 247 176 146; 214 | 247 174 145; 215 | 247 173 143; 216 | 247 172 141; 217 | 247 170 140; 218 | 247 169 138; 219 | 247 167 137; 220 | 247 166 135; 221 | 246 164 134; 222 | 246 163 132; 223 | 246 161 131; 224 | 246 160 129; 225 | 245 158 127; 226 | 245 157 126; 227 | 245 155 124; 228 | 244 154 123; 229 | 244 152 121; 230 | 244 151 120; 231 | 243 149 118; 232 | 243 147 117; 233 | 242 146 115; 234 | 242 144 114; 235 | 241 142 112; 236 | 241 141 111; 237 | 240 139 109; 238 | 240 137 108; 239 | 239 136 106; 240 | 238 134 105; 241 | 238 132 103; 242 | 237 130 102; 243 | 236 129 100; 244 | 236 127 99; 245 | 235 125 97; 246 | 234 123 96; 247 | 233 121 95; 248 | 233 120 93; 249 | 232 118 92; 250 | 231 116 90; 251 | 230 114 89; 252 | 229 112 88; 253 | 228 110 86; 254 | 227 108 85; 255 | 227 106 83; 256 | 226 104 82; 257 | 225 102 81; 258 | 224 100 79; 259 | 223 98 78; 260 | 222 96 77; 261 | 221 94 75; 262 | 220 92 74; 263 | 218 90 73; 264 | 217 88 71; 265 | 216 86 70; 266 | 215 84 69; 267 | 214 82 67; 268 | 213 80 66; 269 | 212 78 65; 270 | 210 75 64; 271 | 209 73 62; 272 | 208 71 61; 273 | 207 69 60; 274 | 205 66 59; 275 | 204 64 57; 276 | 203 62 56; 277 | 202 59 55; 278 | 200 57 54; 279 | 199 54 53; 280 | 198 51 52; 281 | 196 49 50; 282 | 195 46 49; 283 | 193 43 48; 284 | 192 40 47; 285 | 190 37 46; 286 | 189 34 45; 287 | 188 30 44; 288 | 186 26 43; 289 | 185 22 41; 290 | 183 17 40; 291 | 181 11 39; 292 | 180 4 38]; 293 | %... Interpolate get requested size for color table 294 | pp=1:(m-1)/(size(c,1)-1):m; 295 | r=interp1(pp,c(:,1),1:m); 296 | g=interp1(pp,c(:,2),1:m); 297 | b=interp1(pp,c(:,3),1:m); 298 | %... Normalize to range [0,1], and divide again by maximum value 299 | % to correct for round-off errors associated with the interpolation. 300 | map=[r' g' b']/255; 301 | map = map/max(map(:)); 302 | 303 | 304 | -------------------------------------------------------------------------------- /colormaps/hklcolor.m: -------------------------------------------------------------------------------- 1 | function map = hklcolor(m) 2 | %hklcolor color map 3 | % hklcolor(M) returns an M-by-3 matrix containing a colormap with cool-to-warm 4 | % colors, as commonly used in Paraview. 5 | % rdylbu, by itself, is the same length as the current colormap. 6 | % 7 | % For example, to reset the colormap of the current figure: 8 | % 9 | % colormap(hklcolor) 10 | % 11 | % The code structure follows coolwarm.m by Mark Brandon (Yale). 12 | 13 | % Christopher Thissen 14 | % Yale University 15 | % Time-stamp: 16 | %% Check inputs 17 | narginchk(0,1); 18 | 19 | if nargin == 1 20 | validateattributes(m,{'numeric'},{'numel',1}); 21 | end 22 | 23 | %% Begin Function 24 | if nargin < 1, m = size(get(gcf,'colormap'),1); end 25 | c = ... 26 | [ 42.0000 61.0000 153.0000 27 | 40.7911 62.5255 153.9786 28 | 39.5822 64.0510 154.9572 29 | 38.3734 65.5765 155.9358 30 | 37.1645 67.1020 156.9145 31 | 35.9556 68.6275 157.8931 32 | 34.7467 70.1529 158.8717 33 | 33.5378 71.6784 159.8503 34 | 32.3290 73.2039 160.8289 35 | 31.1201 74.7294 161.8075 36 | 29.9112 76.2549 162.7862 37 | 28.7023 77.7804 163.7648 38 | 27.4935 79.3059 164.7434 39 | 26.2846 80.8314 165.7220 40 | 25.0757 82.3569 166.7006 41 | 23.8668 83.8824 167.6792 42 | 22.6579 85.4078 168.6579 43 | 21.4491 86.9333 169.6365 44 | 20.2402 88.4588 170.6151 45 | 19.0313 89.9843 171.5937 46 | 17.8224 91.5098 172.5723 47 | 16.6135 93.0353 173.5509 48 | 15.4047 94.5608 174.5296 49 | 14.1958 96.0863 175.5082 50 | 12.9869 97.6118 176.4868 51 | 11.7780 99.1373 177.4654 52 | 10.5691 100.6627 178.4440 53 | 9.3603 102.1882 179.4226 54 | 8.1514 103.7137 180.4013 55 | 6.9425 105.2392 181.3799 56 | 5.7336 106.7647 182.3585 57 | 4.5248 108.2902 183.3371 58 | 3.3159 109.8157 184.3157 59 | 2.1070 111.3412 185.2943 60 | 0.8981 112.8667 186.2730 61 | 0 114.4518 186.5482 62 | 0 116.2095 184.7905 63 | 0 117.9671 183.0329 64 | 0 119.7247 181.2753 65 | 0 121.4824 179.5176 66 | 0 123.2400 177.7600 67 | 0 124.9976 176.0024 68 | 0 126.7552 174.2448 69 | 0 128.5129 172.4871 70 | 0 130.2705 170.7295 71 | 0 132.0281 168.9719 72 | 0 133.7858 167.2142 73 | 0 135.5434 165.4566 74 | 0 137.3010 163.6990 75 | 0 139.0587 161.9413 76 | 0 140.8163 160.1837 77 | 0 142.5739 158.4261 78 | 0 144.3315 156.6685 79 | 0 146.0892 154.9108 80 | 0 147.8468 153.1532 81 | 0 149.6044 151.3956 82 | 0 151.3621 149.6379 83 | 0 153.1197 147.8803 84 | 0 154.8773 146.1227 85 | 0 156.6350 144.3650 86 | 0 158.3926 142.6074 87 | 0 160.1502 140.8498 88 | 0 161.9078 139.0922 89 | 0 163.6655 137.3345 90 | 0 165.4231 135.5769 91 | 0 167.0139 133.8083 92 | 0 167.1495 131.9438 93 | 0 167.2851 130.0793 94 | 0 167.4207 128.2148 95 | 0 167.5563 126.3503 96 | 0 167.6919 124.4858 97 | 0 167.8275 122.6214 98 | 0 167.9631 120.7569 99 | 0 168.0987 118.8924 100 | 0 168.2343 117.0279 101 | 0 168.3699 115.1634 102 | 0 168.5055 113.2989 103 | 0 168.6411 111.4344 104 | 0 168.7767 109.5699 105 | 0 168.9123 107.7054 106 | 0 169.0479 105.8410 107 | 0 169.1835 103.9765 108 | 0 169.3191 102.1120 109 | 0 169.4547 100.2475 110 | 0 169.5903 98.3830 111 | 0 169.7259 96.5185 112 | 0 169.8615 94.6540 113 | 0 169.9971 92.7895 114 | 0 170.1327 90.9251 115 | 0 170.2683 89.0606 116 | 0 170.4039 87.1961 117 | 0 170.5395 85.3316 118 | 0 170.6751 83.4671 119 | 0 170.8107 81.6026 120 | 0 170.9463 79.7381 121 | 2.0159 171.3456 78.8272 122 | 5.3529 171.9176 78.5412 123 | 8.6900 172.4897 78.2551 124 | 12.0270 173.0618 77.9691 125 | 15.3640 173.6338 77.6831 126 | 18.7010 174.2059 77.3971 127 | 22.0380 174.7779 77.1110 128 | 25.3750 175.3500 76.8250 129 | 28.7120 175.9221 76.5390 130 | 32.0490 176.4941 76.2529 131 | 35.3860 177.0662 75.9669 132 | 38.7230 177.6382 75.6809 133 | 42.0600 178.2103 75.3949 134 | 45.3971 178.7824 75.1088 135 | 48.7341 179.3544 74.8228 136 | 52.0711 179.9265 74.5368 137 | 55.4081 180.4985 74.2507 138 | 58.7451 181.0706 73.9647 139 | 62.0821 181.6426 73.6787 140 | 65.4191 182.2147 73.3926 141 | 68.7561 182.7868 73.1066 142 | 72.9471 183.6507 72.6555 143 | 77.6456 184.6880 72.1064 144 | 82.3442 185.7253 71.5572 145 | 87.0427 186.7627 71.0080 146 | 91.7412 187.8000 70.4588 147 | 96.4397 188.8373 69.9096 148 | 101.1382 189.8747 69.3605 149 | 105.8367 190.9120 68.8113 150 | 110.5352 191.9493 68.2621 151 | 115.2337 192.9867 67.7129 152 | 119.9322 194.0240 67.1638 153 | 124.6307 195.0613 66.6146 154 | 129.3293 196.0987 66.0654 155 | 134.0278 197.1360 65.5162 156 | 138.7263 198.1733 64.9671 157 | 143.4248 199.2107 64.4179 158 | 147.9899 200.4038 63.7525 159 | 152.1305 202.0927 62.7174 160 | 156.2711 203.7817 61.6822 161 | 160.4118 205.4706 60.6471 162 | 164.5524 207.1595 59.6119 163 | 168.6930 208.8485 58.5768 164 | 172.8336 210.5374 57.5416 165 | 176.9742 212.2263 56.5064 166 | 181.1148 213.9153 55.4713 167 | 185.2555 215.6042 54.4361 168 | 189.3961 217.2931 53.4010 169 | 193.5367 218.9821 52.3658 170 | 197.6773 220.6710 51.3307 171 | 201.8179 222.3599 50.2955 172 | 205.9585 224.0489 49.2604 173 | 210.0992 225.7378 48.2252 174 | 214.2398 227.4268 47.1901 175 | 218.3804 229.1157 46.1549 176 | 222.5210 230.8046 45.1197 177 | 223.7783 230.2736 44.7925 178 | 224.6584 229.4522 44.5578 179 | 225.5385 228.6308 44.3231 180 | 226.4186 227.8094 44.0884 181 | 227.2986 226.9879 43.8537 182 | 228.1787 226.1665 43.6190 183 | 229.0588 225.3451 43.3843 184 | 229.9389 224.5237 43.1496 185 | 230.8190 223.7023 42.9149 186 | 231.6991 222.8808 42.6802 187 | 232.5792 222.0594 42.4456 188 | 233.4593 221.2380 42.2109 189 | 234.3394 220.4166 41.9762 190 | 235.2195 219.5952 41.7415 191 | 236.0995 218.7738 41.5068 192 | 236.9796 217.9523 41.2721 193 | 237.8597 217.1309 41.0374 194 | 238.7398 216.3095 40.8027 195 | 239.6199 215.4881 40.5680 196 | 240.5000 214.6667 40.3333 197 | 241.3801 213.8452 40.0986 198 | 242.2602 213.0238 39.8640 199 | 243.1403 212.2024 39.6293 200 | 244.0204 211.3810 39.3946 201 | 244.9005 210.5596 39.1599 202 | 245.7805 209.7382 38.9252 203 | 246.6606 208.9167 38.6905 204 | 247.5407 208.0953 38.4558 205 | 248.4208 207.2739 38.2211 206 | 249.3009 206.4525 37.9864 207 | 250.1810 205.6311 37.7517 208 | 251.0611 204.8097 37.5170 209 | 251.9412 203.9882 37.2824 210 | 252.8213 203.1668 37.0477 211 | 252.6036 200.6743 37.3436 212 | 252.1061 197.7560 37.7747 213 | 251.6087 194.8377 38.2058 214 | 251.1113 191.9194 38.6369 215 | 250.6138 189.0010 39.0680 216 | 250.1164 186.0827 39.4991 217 | 249.6189 183.1644 39.9303 218 | 249.1215 180.2460 40.3614 219 | 248.6240 177.3277 40.7925 220 | 248.1266 174.4094 41.2236 221 | 247.6292 171.4910 41.6547 222 | 247.1317 168.5727 42.0858 223 | 246.6343 165.6544 42.5170 224 | 246.1368 162.7361 42.9481 225 | 245.6394 159.8177 43.3792 226 | 245.1419 156.8994 43.8103 227 | 244.6445 153.9811 44.2414 228 | 244.1471 151.0627 44.6725 229 | 243.6496 148.1444 45.1037 230 | 243.1522 145.2261 45.5348 231 | 242.6547 142.3078 45.9659 232 | 242.1573 139.3894 46.3970 233 | 241.6598 136.4711 46.8281 234 | 241.1624 133.5528 47.2592 235 | 240.6650 130.6344 47.6904 236 | 240.1675 127.7161 48.1215 237 | 239.6701 124.7978 48.5526 238 | 239.1726 121.8795 48.9837 239 | 238.6752 118.9611 49.4148 240 | 238.1777 116.0428 49.8460 241 | 237.9526 113.8931 49.9526 242 | 237.8787 112.1708 49.8787 243 | 237.8049 110.4485 49.8049 244 | 237.7311 108.7261 49.7311 245 | 237.6573 107.0038 49.6573 246 | 237.5835 105.2815 49.5835 247 | 237.5097 103.5591 49.5097 248 | 237.4359 101.8368 49.4359 249 | 237.3620 100.1145 49.3620 250 | 237.2882 98.3922 49.2882 251 | 237.2144 96.6698 49.2144 252 | 237.1406 94.9475 49.1406 253 | 237.0668 93.2252 49.0668 254 | 236.9930 91.5028 48.9930 255 | 236.9192 89.7805 48.9192 256 | 236.8454 88.0582 48.8454 257 | 236.7715 86.3359 48.7715 258 | 236.6977 84.6135 48.6977 259 | 236.6239 82.8912 48.6239 260 | 236.5501 81.1689 48.5501 261 | 236.4763 79.4466 48.4763 262 | 236.4025 77.7242 48.4025 263 | 236.3287 76.0019 48.3287 264 | 236.2548 74.2796 48.2548 265 | 236.1810 72.5572 48.1810 266 | 236.1072 70.8349 48.1072 267 | 236.0334 69.1126 48.0334 268 | 235.9596 67.3903 47.9596 269 | 235.8858 65.6679 47.8858 270 | 235.8120 63.9456 47.8120 271 | 235.7381 62.2233 47.7381 272 | 235.6643 60.5009 47.6643 273 | 235.5905 58.7786 47.5905 274 | 235.5167 57.0563 47.5167 275 | 235.4429 55.3340 47.4429 276 | 235.3691 53.6116 47.3691 277 | 235.2953 51.8893 47.2953 278 | 235.2214 50.1670 47.2214 279 | 235.1476 48.4447 47.1476 280 | 235.0738 46.7223 47.0738 281 | 235.0000 45.0000 47.0000]; 282 | 283 | 284 | 285 | 286 | %... Interpolate get requested size for color table 287 | pp=1:(m-1)/(size(c,1)-1):m; 288 | r=interp1(pp,c(:,1),1:m); 289 | g=interp1(pp,c(:,2),1:m); 290 | b=interp1(pp,c(:,3),1:m); 291 | %... Normalize to range [0,1], and divide again by maximum value 292 | % to correct for round-off errors associated with the interpolation. 293 | map=[r' g' b']/256; 294 | map = map/max(map(:)); 295 | 296 | 297 | %% original color file 298 | % x = ([30 83 129 174 206 231 259 311 357 419]-30)/(419-30); 299 | % cOrig = [ ... 300 | % 042 061 153; 301 | % 000 114 187; 302 | % 000 167 134; 303 | % 000 171 079; 304 | % 070 183 073; 305 | % 147 200 064; 306 | % 223 231 045; 307 | % 253 203 037; 308 | % 238 115 050; 309 | % 235 045 047;]; 310 | % 311 | % xI = linspace(0,1,256); 312 | % rI = interp1(x,cOrig(:,1),xI)'; 313 | % gI = interp1(x,cOrig(:,2),xI)'; 314 | % bI = interp1(x,cOrig(:,3),xI)'; 315 | % c = [rI,gI,bI] 316 | 317 | 318 | 319 | 320 | 321 | 322 | 323 | 324 | 325 | 326 | 327 | 328 | 329 | -------------------------------------------------------------------------------- /colormaps/rdylbu.m: -------------------------------------------------------------------------------- 1 | function map = rdylbu(m) 2 | %rdylbu color map 3 | % rdylbu(M) returns an M-by-3 matrix containing a colormap with cool-to-warm 4 | % colors, as commonly used in Paraview. 5 | % rdylbu, by itself, is the same length as the current colormap. 6 | % 7 | % For example, to reset the colormap of the current figure: 8 | % 9 | % colormap(rdylbu) 10 | 11 | % Christopher Thissen 12 | % Yale University 13 | % Time-stamp: 14 | %% Check inputs 15 | narginchk(0,1); 16 | 17 | if nargin == 1 18 | validateattributes(m,{'numeric'},{'numel',1}); 19 | end 20 | 21 | %% Begin Function 22 | if nargin < 1, m = size(get(gcf,'colormap'),1); end 23 | c = ... 24 | [ 146.0000 0 29.0000 25 | 147.9572 1.2952 29.2303 26 | 149.9145 2.5905 29.4605 27 | 151.8717 3.8857 29.6908 28 | 153.8289 5.1809 29.9211 29 | 155.7862 6.4761 30.1513 30 | 157.7434 7.7714 30.3816 31 | 159.7006 9.0666 30.6118 32 | 161.6579 10.3618 30.8421 33 | 163.6151 11.6570 31.0724 34 | 165.5723 12.9523 31.3026 35 | 167.5296 14.2475 31.5329 36 | 169.4868 15.5427 31.7632 37 | 171.4440 16.8380 31.9934 38 | 173.4013 18.1332 32.2237 39 | 175.3585 19.4284 32.4539 40 | 177.3157 20.7236 32.6842 41 | 179.2730 22.0189 32.9145 42 | 181.2302 23.3141 33.1447 43 | 183.1874 24.6093 33.3750 44 | 185.1447 25.9046 33.6053 45 | 187.1019 27.1998 33.8355 46 | 189.0591 28.4950 34.0658 47 | 191.0164 29.7902 34.2960 48 | 192.9736 31.0855 34.5263 49 | 194.9308 32.3807 34.7566 50 | 196.8881 33.6759 34.9868 51 | 198.8453 34.9711 35.2171 52 | 200.8025 36.2664 35.4474 53 | 202.7597 37.5616 35.6776 54 | 204.7170 38.8568 35.9079 55 | 206.6742 40.1521 36.1381 56 | 208.6314 41.4473 36.3684 57 | 210.5887 42.7425 36.5987 58 | 212.5459 44.0377 36.8289 59 | 214.2558 45.6479 37.2387 60 | 215.2506 48.1683 38.1673 61 | 216.2455 50.6887 39.0958 62 | 217.2404 53.2090 40.0244 63 | 218.2353 55.7294 40.9529 64 | 219.2302 58.2498 41.8815 65 | 220.2251 60.7702 42.8101 66 | 221.2199 63.2905 43.7386 67 | 222.2148 65.8109 44.6672 68 | 223.2097 68.3313 45.5957 69 | 224.2046 70.8517 46.5243 70 | 225.1995 73.3720 47.4529 71 | 226.1944 75.8924 48.3814 72 | 227.1893 78.4128 49.3100 73 | 228.1841 80.9332 50.2385 74 | 229.1790 83.4535 51.1671 75 | 230.1739 85.9739 52.0957 76 | 231.1688 88.4943 53.0242 77 | 232.1637 91.0147 53.9528 78 | 233.1586 93.5350 54.8813 79 | 234.1535 96.0554 55.8099 80 | 235.1483 98.5758 56.7384 81 | 236.1432 101.0962 57.6670 82 | 237.1381 103.6165 58.5956 83 | 238.1330 106.1369 59.5241 84 | 239.1279 108.6573 60.4527 85 | 240.1228 111.1777 61.3812 86 | 241.1176 113.6980 62.3098 87 | 242.1125 116.2184 63.2384 88 | 243.1074 118.7388 64.1669 89 | 244.0244 121.2649 65.1534 90 | 244.2617 123.8413 66.6450 91 | 244.4990 126.4177 68.1366 92 | 244.7363 128.9941 69.6281 93 | 244.9736 131.5705 71.1197 94 | 245.2109 134.1468 72.6113 95 | 245.4482 136.7232 74.1029 96 | 245.6855 139.2996 75.5945 97 | 245.9228 141.8760 77.0861 98 | 246.1601 144.4524 78.5777 99 | 246.3974 147.0288 80.0693 100 | 246.6347 149.6051 81.5609 101 | 246.8720 152.1815 83.0525 102 | 247.1093 154.7579 84.5441 103 | 247.3466 157.3343 86.0356 104 | 247.5839 159.9107 87.5272 105 | 247.8212 162.4871 89.0188 106 | 248.0585 165.0634 90.5104 107 | 248.2958 167.6398 92.0020 108 | 248.5331 170.2162 93.4936 109 | 248.7704 172.7926 94.9852 110 | 249.0077 175.3690 96.4768 111 | 249.2450 177.9454 97.9684 112 | 249.4823 180.5217 99.4600 113 | 249.7196 183.0981 100.9515 114 | 249.9569 185.6745 102.4431 115 | 250.1942 188.2509 103.9347 116 | 250.4315 190.8273 105.4263 117 | 250.6688 193.4037 106.9179 118 | 250.9061 195.9800 108.4095 119 | 251.0576 198.1808 110.2096 120 | 251.1529 200.1353 112.2118 121 | 251.2483 202.0898 114.2140 122 | 251.3436 204.0444 116.2162 123 | 251.4390 205.9989 118.2184 124 | 251.5343 207.9534 120.2206 125 | 251.6297 209.9080 122.2228 126 | 251.7250 211.8625 124.2250 127 | 251.8203 213.8170 126.2272 128 | 251.9157 215.7716 128.2294 129 | 252.0110 217.7261 130.2316 130 | 252.1064 219.6806 132.2338 131 | 252.2017 221.6352 134.2360 132 | 252.2971 223.5897 136.2382 133 | 252.3924 225.5442 138.2404 134 | 252.4877 227.4988 140.2426 135 | 252.5831 229.4533 142.2449 136 | 252.6784 231.4078 144.2471 137 | 252.7738 233.3624 146.2493 138 | 252.8691 235.3169 148.2515 139 | 252.9645 237.2714 150.2537 140 | 252.8469 238.6124 152.3396 141 | 252.6028 239.5887 154.4753 142 | 252.3587 240.5650 156.6110 143 | 252.1147 241.5413 158.7467 144 | 251.8706 242.5176 160.8824 145 | 251.6265 243.4940 163.0180 146 | 251.3824 244.4703 165.1537 147 | 251.1384 245.4466 167.2894 148 | 250.8943 246.4229 169.4251 149 | 250.6502 247.3992 171.5608 150 | 250.4061 248.3755 173.6965 151 | 250.1620 249.3518 175.8322 152 | 249.9180 250.3282 177.9678 153 | 249.6739 251.3045 180.1035 154 | 249.4298 252.2808 182.2392 155 | 249.1857 253.2571 184.3749 156 | 248.6353 253.8437 186.6513 157 | 247.1098 253.1899 189.3754 158 | 245.5843 252.5361 192.0994 159 | 244.0588 251.8824 194.8235 160 | 242.5333 251.2286 197.5476 161 | 241.0078 250.5748 200.2717 162 | 239.4824 249.9210 202.9958 163 | 237.9569 249.2672 205.7199 164 | 236.4314 248.6134 208.4440 165 | 234.9059 247.9597 211.1681 166 | 233.3804 247.3059 213.8922 167 | 231.8549 246.6521 216.6162 168 | 230.3294 245.9983 219.3403 169 | 228.8039 245.3445 222.0644 170 | 227.2784 244.6908 224.7885 171 | 225.7529 244.0370 227.5126 172 | 224.2275 243.3832 230.2367 173 | 222.7020 242.7294 232.9608 174 | 221.1765 242.0756 235.6849 175 | 218.9765 240.8585 235.5849 176 | 216.6882 239.5677 235.1155 177 | 214.4000 238.2769 234.6462 178 | 212.1118 236.9861 234.1768 179 | 209.8235 235.6953 233.7074 180 | 207.5353 234.4045 233.2380 181 | 205.2471 233.1137 232.7686 182 | 202.9588 231.8229 232.2992 183 | 200.6706 230.5321 231.8299 184 | 198.3824 229.2413 231.3605 185 | 196.0941 227.9505 230.8911 186 | 193.8059 226.6597 230.4217 187 | 191.5176 225.3689 229.9523 188 | 189.2294 224.0781 229.4830 189 | 186.9412 222.7873 229.0136 190 | 184.6529 221.4965 228.5442 191 | 182.3647 220.2057 228.0748 192 | 180.0765 218.9149 227.6054 193 | 177.7882 217.6241 227.1360 194 | 175.5000 216.3333 226.6667 195 | 173.2118 215.0425 226.1973 196 | 170.9235 213.7517 225.7279 197 | 168.6353 212.4609 225.2585 198 | 166.3471 211.1701 224.7891 199 | 164.0588 209.8793 224.3198 200 | 161.7706 208.5885 223.8504 201 | 159.4824 207.2977 223.3810 202 | 157.1941 206.0069 222.9116 203 | 154.9059 204.7161 222.4422 204 | 152.6176 203.4253 221.9729 205 | 150.3294 202.1345 221.5035 206 | 148.0412 200.8437 221.0341 207 | 145.7529 199.5529 220.5647 208 | 143.4647 198.2621 220.0953 209 | 141.3086 196.2029 219.0222 210 | 139.1862 193.9478 217.7951 211 | 137.0638 191.6928 216.5681 212 | 134.9413 189.4377 215.3411 213 | 132.8189 187.1826 214.1141 214 | 130.6965 184.9275 212.8870 215 | 128.5741 182.6725 211.6600 216 | 126.4517 180.4174 210.4330 217 | 124.3292 178.1623 209.2060 218 | 122.2068 175.9072 207.9789 219 | 120.0844 173.6522 206.7519 220 | 117.9620 171.3971 205.5249 221 | 115.8396 169.1420 204.2979 222 | 113.7171 166.8870 203.0708 223 | 111.5947 164.6319 201.8438 224 | 109.4723 162.3768 200.6168 225 | 107.3499 160.1217 199.3898 226 | 105.2275 157.8667 198.1627 227 | 103.1050 155.6116 196.9357 228 | 100.9826 153.3565 195.7087 229 | 98.8602 151.1014 194.4817 230 | 96.7378 148.8464 193.2546 231 | 94.6153 146.5913 192.0276 232 | 92.4929 144.3362 190.8006 233 | 90.3705 142.0812 189.5736 234 | 88.2481 139.8261 188.3465 235 | 86.1257 137.5710 187.1195 236 | 84.0032 135.3159 185.8925 237 | 81.8808 133.0609 184.6655 238 | 79.7584 130.8058 183.4384 239 | 78.3359 128.5136 182.1619 240 | 77.3025 126.2008 180.8579 241 | 76.2691 123.8879 179.5538 242 | 75.2357 121.5751 178.2498 243 | 74.2023 119.2622 176.9457 244 | 73.1689 116.9494 175.6417 245 | 72.1355 114.6366 174.3376 246 | 71.1021 112.3237 173.0336 247 | 70.0687 110.0109 171.7295 248 | 69.0353 107.6980 170.4255 249 | 68.0019 105.3852 169.1214 250 | 66.9685 103.0724 167.8174 251 | 65.9351 100.7595 166.5133 252 | 64.9017 98.4467 165.2093 253 | 63.8683 96.1338 163.9052 254 | 62.8349 93.8210 162.6012 255 | 61.8015 91.5082 161.2972 256 | 60.7681 89.1953 159.9931 257 | 59.7347 86.8825 158.6891 258 | 58.7013 84.5696 157.3850 259 | 57.6679 82.2568 156.0810 260 | 56.6345 79.9440 154.7769 261 | 55.6011 77.6311 153.4729 262 | 54.5677 75.3183 152.1688 263 | 53.5343 73.0054 150.8648 264 | 52.5009 70.6926 149.5607 265 | 51.4676 68.3798 148.2567 266 | 50.4342 66.0669 146.9526 267 | 49.4008 63.7541 145.6486 268 | 48.3674 61.4412 144.3445 269 | 47.3340 59.1284 143.0405 270 | 46.3006 56.8156 141.7364 271 | 45.2672 54.5027 140.4324 272 | 44.2338 52.1899 139.1283 273 | 43.2004 49.8770 137.8243 274 | 42.1670 47.5642 136.5202 275 | 41.1336 45.2514 135.2162 276 | 40.1002 42.9385 133.9121 277 | 39.0668 40.6257 132.6081 278 | 38.0334 38.3128 131.3040 279 | 37.0000 36.0000 130.0000]; 280 | 281 | 282 | 283 | 284 | %... Interpolate get requested size for color table 285 | pp=1:(m-1)/(size(c,1)-1):m; 286 | r=interp1(pp,c(:,1),1:m); 287 | g=interp1(pp,c(:,2),1:m); 288 | b=interp1(pp,c(:,3),1:m); 289 | %... Normalize to range [0,1], and divide again by maximum value 290 | % to correct for round-off errors associated with the interpolation. 291 | map=[r' g' b']/256; 292 | map = map/max(map(:)); 293 | 294 | 295 | %% cpt file is incorrect. 296 | % a correct was created using photoshop's color sampler tool 297 | % x = ([30 83 129 174 206 231 259 311 357 419]-30)/(419-30); 298 | % cOrig = [ ... 299 | % 146 0 29; 300 | % 214 45 37; 301 | % 244 121 65; 302 | % 251 197 109; 303 | % 253 238 151; 304 | % 249 254 186; 305 | % 221 242 236; 306 | % 143 198 220; 307 | % 079 130 183; 308 | % 037 036 130]; 309 | % 310 | % xI = linspace(0,1,256); 311 | % rI = interp1(x,cOrig(:,1),xI)'; 312 | % gI = interp1(x,cOrig(:,2),xI)'; 313 | % bI = interp1(x,cOrig(:,3),xI)'; 314 | % c = [rI,gI,bI] 315 | 316 | 317 | 318 | -------------------------------------------------------------------------------- /colormaps/test_colormaps.m: -------------------------------------------------------------------------------- 1 | 2 | 3 | % test colormaps 4 | 5 | nColors = 256; 6 | cMap(1).map = algae(nColors); 7 | cMap(2).map = virus(nColors); 8 | cMap(3).map = coolwarm(nColors); 9 | cMap(4).map = hklcolor(nColors); 10 | cMap(5).map = rdylbu(nColors); 11 | 12 | cMap(1).name = 'algae'; 13 | cMap(2).name = 'virus'; 14 | cMap(3).name = 'coolwarm'; 15 | cMap(4).name = 'hklcolor'; 16 | cMap(5).name = 'rdylbu'; 17 | 18 | 19 | close all 20 | hFig = figure(1); clf 21 | 22 | nCmap = numel(cMap); 23 | fontSize = 14; 24 | 25 | % calculate spacing 26 | vertWidth = 0.05; 27 | vertPos = 1/(nCmap + 3*nCmap*vertWidth); 28 | 29 | for i = 1:nCmap; 30 | h(i) = axes('units','normalized','pos',[0 0 1 1],... 31 | 'visible','off','handlevisibility','off'); 32 | hCbar = colorbar(h(i)); 33 | hCbar.Location = 'southoutside'; % makes colorbar hz 34 | colormap(h(i),cMap(i).map); 35 | hCbar.Position = [0.1, i*vertPos, 0.8, vertWidth]; 36 | hCbar.Label.String = cMap(i).name; 37 | 38 | hCbar.FontSize = fontSize; 39 | hCbar.Label.FontSize = fontSize; 40 | end 41 | 42 | 43 | 44 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /colormaps/virus.m: -------------------------------------------------------------------------------- 1 | function map = virus(m) 2 | %virus color map 3 | % virus(M) returns an M-by-3 matrix containing a colormap with cool-to-warm 4 | % colors, as commonly used in Paraview. 5 | % rdylbu, by itself, is the same length as the current colormap. 6 | % 7 | % For example, to reset the colormap of the current figure: 8 | % 9 | % colormap(virus) 10 | % 11 | % The code structure follows coolwarm.m by Mark Brandon (Yale). 12 | 13 | % Christopher Thissen 14 | % Yale University 15 | % Time-stamp: 16 | %% Check inputs 17 | narginchk(0,1); 18 | 19 | if nargin == 1 20 | validateattributes(m,{'numeric'},{'numel',1}); 21 | end 22 | 23 | %% Begin Function 24 | if nargin < 1, m = size(get(gcf,'colormap'),1); end 25 | c = ... 26 | [ 0 0 6.0000 27 | 0 0.4078 8.1647 28 | 0 0.8157 10.3294 29 | 0 1.2235 12.4941 30 | 0 1.6314 14.6588 31 | 0 2.0392 16.8235 32 | 0 2.4471 18.9882 33 | 0 2.8549 21.1529 34 | 0 3.2627 23.3176 35 | 0 3.6706 25.4824 36 | 0 4.0784 27.6471 37 | 0 4.4863 29.8118 38 | 0 4.8941 31.9765 39 | 0 5.3020 34.1412 40 | 0 5.7098 36.3059 41 | 0 6.1176 38.4706 42 | 0 6.5255 40.6353 43 | 0 6.9333 42.8000 44 | 0 7.3412 44.9647 45 | 0 7.7490 47.1294 46 | 0 8.1569 49.2941 47 | 0 8.5647 51.4588 48 | 0 8.9725 53.6235 49 | 0 9.3804 55.7882 50 | 0 9.7882 57.9529 51 | 0 10.1961 60.1176 52 | 0 10.6039 62.2824 53 | 0 11.0118 64.4471 54 | 0 11.4196 66.6118 55 | 0 11.8275 68.7765 56 | 0 12.2353 70.9412 57 | 0 12.6431 73.1059 58 | 0 13.3412 75.0980 59 | 0 16.0706 75.8824 60 | 0 18.8000 76.6667 61 | 0 21.5294 77.4510 62 | 0 24.2588 78.2353 63 | 0 26.9882 79.0196 64 | 0 29.7176 79.8039 65 | 0 32.4471 80.5882 66 | 0 35.1765 81.3725 67 | 0 37.9059 82.1569 68 | 0 40.6353 82.9412 69 | 0 43.3647 83.7255 70 | 0 46.0941 84.5098 71 | 0 48.8235 85.2941 72 | 0 51.5529 86.0784 73 | 0 54.2824 86.8627 74 | 0 57.0118 87.6471 75 | 0 59.7412 88.4314 76 | 0 62.4706 89.2157 77 | 0 65.2000 90.0000 78 | 0 67.9294 90.7843 79 | 0 70.6588 91.5686 80 | 0 73.3882 92.3529 81 | 0 76.1176 93.1373 82 | 0 78.8471 93.9216 83 | 0 81.5765 94.7059 84 | 0 84.3059 95.4902 85 | 0 87.0353 96.2745 86 | 0 89.7647 97.0588 87 | 0 92.4941 97.8431 88 | 0 95.2235 98.6275 89 | 0 97.9529 99.4118 90 | 0 100.3765 99.5451 91 | 0 101.8824 97.7255 92 | 0 103.3882 95.9059 93 | 0 104.8941 94.0863 94 | 0 106.4000 92.2667 95 | 0 107.9059 90.4471 96 | 0 109.4118 88.6275 97 | 0 110.9176 86.8078 98 | 0 112.4235 84.9882 99 | 0 113.9294 83.1686 100 | 0 115.4353 81.3490 101 | 0 116.9412 79.5294 102 | 0 118.4471 77.7098 103 | 0 119.9529 75.8902 104 | 0 121.4588 74.0706 105 | 0 122.9647 72.2510 106 | 0 124.4706 70.4314 107 | 0 125.9765 68.6118 108 | 0 127.4824 66.7922 109 | 0 128.9882 64.9725 110 | 0 130.4941 63.1529 111 | 0 132.0000 61.3333 112 | 0 133.5059 59.5137 113 | 0 135.0118 57.6941 114 | 0 136.5176 55.8745 115 | 0 138.0235 54.0549 116 | 0 139.5294 52.2353 117 | 0 141.0353 50.4157 118 | 0 142.5412 48.5961 119 | 0 144.0471 46.7765 120 | 0 145.5529 44.9569 121 | 0 147.0588 43.1373 122 | 1.3176 147.4706 41.5059 123 | 4.8314 146.0588 40.1882 124 | 8.3451 144.6471 38.8706 125 | 11.8588 143.2353 37.5529 126 | 15.3725 141.8235 36.2353 127 | 18.8863 140.4118 34.9176 128 | 22.4000 139.0000 33.6000 129 | 25.9137 137.5882 32.2824 130 | 29.4275 136.1765 30.9647 131 | 32.9412 134.7647 29.6471 132 | 36.4549 133.3529 28.3294 133 | 39.9686 131.9412 27.0118 134 | 43.4824 130.5294 25.6941 135 | 46.9961 129.1176 24.3765 136 | 50.5098 127.7059 23.0588 137 | 54.0235 126.2941 21.7412 138 | 57.5373 124.8824 20.4235 139 | 61.0510 123.4706 19.1059 140 | 64.5647 122.0588 17.7882 141 | 68.0784 120.6471 16.4706 142 | 71.5922 119.2353 15.1529 143 | 75.1059 117.8235 13.8353 144 | 78.6196 116.4118 12.5176 145 | 82.1333 115.0000 11.2000 146 | 85.6471 113.5882 9.8824 147 | 89.1608 112.1765 8.5647 148 | 92.6745 110.7647 7.2471 149 | 96.1882 109.3529 5.9294 150 | 99.7020 107.9412 4.6118 151 | 103.2157 106.5294 3.2941 152 | 106.7294 105.1176 1.9765 153 | 110.2431 103.7059 0.6588 154 | 113.4902 101.9333 0 155 | 116.4706 99.8000 0 156 | 119.4510 97.6667 0 157 | 122.4314 95.5333 0 158 | 125.4118 93.4000 0 159 | 128.3922 91.2667 0 160 | 131.3725 89.1333 0 161 | 134.3529 87.0000 0 162 | 137.3333 84.8667 0 163 | 140.3137 82.7333 0 164 | 143.2941 80.6000 0 165 | 146.2745 78.4667 0 166 | 149.2549 76.3333 0 167 | 152.2353 74.2000 0 168 | 155.2157 72.0667 0 169 | 158.1961 69.9333 0 170 | 161.1765 67.8000 0 171 | 164.1569 65.6667 0 172 | 167.1373 63.5333 0 173 | 170.1176 61.4000 0 174 | 173.0980 59.2667 0 175 | 176.0784 57.1333 0 176 | 179.0588 55.0000 0 177 | 182.0392 52.8667 0 178 | 185.0196 50.7333 0 179 | 188.0000 48.6000 0 180 | 190.9804 46.4667 0 181 | 193.9608 44.3333 0 182 | 196.9412 42.2000 0 183 | 199.9216 40.0667 0 184 | 202.9020 37.9333 0 185 | 205.8824 35.8000 0 186 | 207.3333 36.5098 0 187 | 207.8667 38.9255 0 188 | 208.4000 41.3412 0 189 | 208.9333 43.7569 0 190 | 209.4667 46.1725 0 191 | 210.0000 48.5882 0 192 | 210.5333 51.0039 0 193 | 211.0667 53.4196 0 194 | 211.6000 55.8353 0 195 | 212.1333 58.2510 0 196 | 212.6667 60.6667 0 197 | 213.2000 63.0824 0 198 | 213.7333 65.4980 0 199 | 214.2667 67.9137 0 200 | 214.8000 70.3294 0 201 | 215.3333 72.7451 0 202 | 215.8667 75.1608 0 203 | 216.4000 77.5765 0 204 | 216.9333 79.9922 0 205 | 217.4667 82.4078 0 206 | 218.0000 84.8235 0 207 | 218.5333 87.2392 0 208 | 219.0667 89.6549 0 209 | 219.6000 92.0706 0 210 | 220.1333 94.4863 0 211 | 220.6667 96.9020 0 212 | 221.2000 99.3176 0 213 | 221.7333 101.7333 0 214 | 222.2667 104.1490 0 215 | 222.8000 106.5647 0 216 | 223.3333 108.9804 0 217 | 223.8667 111.3961 0 218 | 224.3529 113.5765 0 219 | 224.8235 115.6784 0 220 | 225.2941 117.7804 0 221 | 225.7647 119.8824 0 222 | 226.2353 121.9843 0 223 | 226.7059 124.0863 0 224 | 227.1765 126.1882 0 225 | 227.6471 128.2902 0 226 | 228.1176 130.3922 0 227 | 228.5882 132.4941 0 228 | 229.0588 134.5961 0 229 | 229.5294 136.6980 0 230 | 230.0000 138.8000 0 231 | 230.4706 140.9020 0 232 | 230.9412 143.0039 0 233 | 231.4118 145.1059 0 234 | 231.8824 147.2078 0 235 | 232.3529 149.3098 0 236 | 232.8235 151.4118 0 237 | 233.2941 153.5137 0 238 | 233.7647 155.6157 0 239 | 234.2353 157.7176 0 240 | 234.7059 159.8196 0 241 | 235.1765 161.9216 0 242 | 235.6471 164.0235 0 243 | 236.1176 166.1255 0 244 | 236.5882 168.2275 0 245 | 237.0588 170.3294 0 246 | 237.5294 172.4314 0 247 | 238.0000 174.5333 0 248 | 238.4706 176.6353 0 249 | 238.9412 178.7373 0 250 | 239.4118 180.9490 0 251 | 239.8824 183.1765 0 252 | 240.3529 185.4039 0 253 | 240.8235 187.6314 0 254 | 241.2941 189.8588 0 255 | 241.7647 192.0863 0 256 | 242.2353 194.3137 0 257 | 242.7059 196.5412 0 258 | 243.1765 198.7686 0 259 | 243.6471 200.9961 0 260 | 244.1176 203.2235 0 261 | 244.5882 205.4510 0 262 | 245.0588 207.6784 0 263 | 245.5294 209.9059 0 264 | 246.0000 212.1333 0 265 | 246.4706 214.3608 0 266 | 246.9412 216.5882 0 267 | 247.4118 218.8157 0 268 | 247.8824 221.0431 0 269 | 248.3529 223.2706 0 270 | 248.8235 225.4980 0 271 | 249.2941 227.7255 0 272 | 249.7647 229.9529 0 273 | 250.2353 232.1804 0 274 | 250.7059 234.4078 0 275 | 251.1765 236.6353 0 276 | 251.6471 238.8627 0 277 | 252.1176 241.0902 0 278 | 252.5882 243.3176 0 279 | 253.0588 245.5451 0 280 | 253.5294 247.7725 0 281 | 254.0000 250.0000 0]; 282 | 283 | 284 | 285 | 286 | %... Interpolate get requested size for color table 287 | pp=1:(m-1)/(size(c,1)-1):m; 288 | r=interp1(pp,c(:,1),1:m); 289 | g=interp1(pp,c(:,2),1:m); 290 | b=interp1(pp,c(:,3),1:m); 291 | %... Normalize to range [0,1], and divide again by maximum value 292 | % to correct for round-off errors associated with the interpolation. 293 | map=[r' g' b']/256; 294 | map = map/max(map(:)); 295 | 296 | %% LINT - Generate c matrix 297 | % interpolate to linear spacing (used to generate c matrix above) 298 | % x = [0:1:8] / 8; 299 | % cOrig = ... 300 | % [ 0 0 6; 301 | % 0 13 75; 302 | % 0 100 100; 303 | % 0 148 42; 304 | % 112 103 0; 305 | % 207 35 0; 306 | % 224 112 0; 307 | % 239 179 0; 308 | % 254 250 0]; 309 | % 310 | % xI = linspace(0,1,256); 311 | % rI = interp1(x,cOrig(:,1),xI)'; 312 | % gI = interp1(x,cOrig(:,2),xI)'; 313 | % bI = interp1(x,cOrig(:,3),xI)'; 314 | % c = [rI,gI,bI] 315 | 316 | %% LINT - original .cpt file 317 | % # autogenerated GMT palette "virus.txt" 318 | % # cptutils version 1.31, Thu Jun 11 01:59:11 2009 319 | % # COLOR_MODEL = RGB 320 | % 0.000000e+00 0 0 6 1.000000e+00 0 13 75 321 | % 1.000000e+00 0 13 75 2.000000e+00 0 100 100 322 | % 2.000000e+00 0 100 100 3.000000e+00 0 148 42 323 | % 3.000000e+00 0 148 42 4.000000e+00 112 103 0 324 | % 4.000000e+00 112 103 0 5.000000e+00 207 35 0 325 | % 5.000000e+00 207 35 0 6.000000e+00 224 112 0 326 | % 6.000000e+00 224 112 0 7.000000e+00 239 179 0 327 | % 7.000000e+00 239 179 0 8.000000e+00 254 250 0 328 | % B 0 0 0 329 | % F 255 255 255 330 | % N 255 0 0 331 | 332 | 333 | 334 | 335 | 336 | 337 | 338 | 339 | 340 | 341 | -------------------------------------------------------------------------------- /dispstat/dispstat.m: -------------------------------------------------------------------------------- 1 | function dispstat(TXT,varargin) 2 | % Prints overwritable message to the command line. If you dont want to keep 3 | % this message, call dispstat function with option 'keepthis'. If you want to 4 | % keep the previous message, use option 'keepprev'. First argument must be 5 | % the message. 6 | % IMPORTANT! In the firt call, option 'init' must be used for initialization purposes. 7 | % Options: 8 | % 'init' this must be called in the begining. Otherwise, it can overwrite the previous outputs on the command line. 9 | % 'keepthis' the message will be persistent, wont be overwritable, 10 | % 'keepprev' the previous message wont be overwritten. New message will start from next line, 11 | % 'timestamp' current time hh:mm:ss will be appended to the begining of the message. 12 | % Example: 13 | % clc; 14 | % fprintf('12345677890\n'); 15 | % dispstat('','init') %Initialization. Does not print anything. 16 | % dispstat('Time stamp will be written over this text.'); % First output 17 | % dispstat('is current time.','timestamp','keepthis'); % Overwrites the previous output but this output wont be overwritten. 18 | % dispstat(sprintf('*********\nDeveloped by %s\n*********','Kasim')); % does not overwrites the previous output 19 | % dispstat('','timestamp','keepprev','keepthis'); % does not overwrites the previous output 20 | % dispstat('this wont be overwriten','keepthis'); 21 | % dispstat('dummy dummy dummy'); 22 | % dispstat('final stat'); 23 | % % Output: 24 | % 12345677890 25 | % 15:15:34 is current time. 26 | % ********* 27 | % Developed by Kasim 28 | % ********* 29 | % 15:15:34 30 | % this wont be overwriten 31 | % final stat 32 | 33 | % ********** 34 | % **** Options 35 | keepthis = 0; % option for not overwriting 36 | keepprev = 0; 37 | timestamp = 0; % time stamp option 38 | init = 0; % is it initialization step? 39 | if ~isstr(TXT) 40 | return 41 | end 42 | persistent prevCharCnt; 43 | if isempty(prevCharCnt) 44 | prevCharCnt = 0; 45 | end 46 | if nargin == 0 47 | return 48 | elseif nargin > 1 49 | for i = 2:nargin 50 | eval([varargin{i-1} '=1;']); 51 | end 52 | end 53 | if init == 1 54 | prevCharCnt = 0; 55 | return; 56 | end 57 | if isempty(TXT) && timestamp == 0 58 | return 59 | end 60 | if timestamp == 1 61 | c = clock; % [year month day hour minute seconds] 62 | txtTimeStamp = sprintf('%02d:%02d:%02d ',c(4),c(5),round(c(6))); 63 | else 64 | txtTimeStamp = ''; 65 | end 66 | if keepprev == 1 67 | prevCharCnt = 0; 68 | end 69 | % *************** Make safe for fprintf, replace control charachters 70 | TXT = strrep(TXT,'%','%%'); 71 | TXT = strrep(TXT,'\','\\'); 72 | % *************** Print 73 | TXT = [txtTimeStamp TXT '\n']; 74 | fprintf([repmat('\b',1, prevCharCnt) TXT]); 75 | nof_extra = length(strfind(TXT,'%%')); 76 | nof_extra = nof_extra + length(strfind(TXT,'\\')); 77 | nof_extra = nof_extra + length(strfind(TXT,'\n')); 78 | prevCharCnt = length(TXT) - nof_extra; %-1 is for \n 79 | if keepthis == 1 80 | prevCharCnt = 0; 81 | end 82 | end -------------------------------------------------------------------------------- /dispstat/license.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2013, kasim tasdemir 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are 6 | met: 7 | 8 | * Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | * Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in 12 | the documentation and/or other materials provided with the distribution 13 | 14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 18 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 19 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 20 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 21 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 22 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 23 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 24 | POSSIBILITY OF SUCH DAMAGE. 25 | -------------------------------------------------------------------------------- /dispstat/test_dispstat.m: -------------------------------------------------------------------------------- 1 | dispstat('','init'); % One time only initialization 2 | dispstat(sprintf('\nBegining the process...'),'keepthis','timestamp'); 3 | for i = 1:100 4 | dispstat(sprintf('Progress %d%%',i),'timestamp'); 5 | pause(0.1) 6 | %doing some heavy stuff here 7 | end 8 | dispstat('Finished.','keepprev'); -------------------------------------------------------------------------------- /export_fig/.gitignore: -------------------------------------------------------------------------------- 1 | /.ignore 2 | *.txt 3 | *.asv 4 | *~ 5 | *.mex* 6 | -------------------------------------------------------------------------------- /export_fig/.ignore/ghostscript.txt: -------------------------------------------------------------------------------- 1 | /usr/local/bin/gs -------------------------------------------------------------------------------- /export_fig/.ignore/gs_font_path.txt: -------------------------------------------------------------------------------- 1 | /usr/share/fonts:/usr/local/share/fonts:/usr/share/fonts/X11:/usr/local/share/fonts/X11:/usr/share/fonts/truetype:/usr/local/share/fonts/truetype -------------------------------------------------------------------------------- /export_fig/ImageSelection.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cthissen/Drex-MATLAB/39da9a38b1783c46fe4f2ac49e1c059e3c313b96/export_fig/ImageSelection.class -------------------------------------------------------------------------------- /export_fig/ImageSelection.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cthissen/Drex-MATLAB/39da9a38b1783c46fe4f2ac49e1c059e3c313b96/export_fig/ImageSelection.java -------------------------------------------------------------------------------- /export_fig/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2014, Oliver J. Woodford, Yair M. Altman 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | 10 | * Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation 12 | and/or other materials provided with the distribution. 13 | 14 | * Neither the name of the {organization} nor the names of its 15 | contributors may be used to endorse or promote products derived from 16 | this software without specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 22 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 24 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 25 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 26 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | -------------------------------------------------------------------------------- /export_fig/README.md: -------------------------------------------------------------------------------- 1 | export_fig 2 | ========== 3 | 4 | A toolbox for exporting figures from MATLAB to standard image and document formats nicely. 5 | 6 | ### Overview 7 | Exporting a figure from MATLAB the way you want it (hopefully the way it looks on screen), can be a real headache for the unitiated, thanks to all the settings that are required, and also due to some eccentricities (a.k.a. features and bugs) of functions such as `print`. The first goal of export_fig is to make transferring a plot from screen to document, just the way you expect (again, assuming that's as it appears on screen), a doddle. 8 | 9 | The second goal is to make the output media suitable for publication, allowing you to publish your results in the full glory that you originally intended. This includes embedding fonts, setting image compression levels (including lossless), anti-aliasing, cropping, setting the colourspace, alpha-blending and getting the right resolution. 10 | 11 | Perhaps the best way to demonstrate what export_fig can do is with some examples. 12 | 13 | ### Examples 14 | **Visual accuracy** - MATLAB's exporting functions, namely `saveas` and `print`, change many visual properties of a figure, such as size, axes limits and ticks, and background colour, in unexpected and unintended ways. Export_fig aims to faithfully reproduce the figure as it appears on screen. For example: 15 | ```Matlab 16 | plot(cos(linspace(0, 7, 1000))); 17 | set(gcf, 'Position', [100 100 150 150]); 18 | saveas(gcf, 'test.png'); 19 | export_fig test2.png 20 | ``` 21 | generates the following: 22 | 23 | | Figure: | test.png: | test2.png: | 24 | |:-------:|:---------:|:----------:| 25 | |![](https://farm6.staticflickr.com/5616/15589249291_16e485c29a_o_d.png)|![](https://farm4.staticflickr.com/3944/15406302850_4d2e1c7afa_o_d.png)|![](https://farm6.staticflickr.com/5607/15568225476_8ce9bd5f6b_o_d.png)| 26 | 27 | Note that the size and background colour of test2.png (the output of export_fig) are the same as those of the on screen figure, in contrast to test.png. Of course, if you want the figure background to be white (or any other colour) in the exported file then you can set this prior to exporting using: 28 | ```Matlab 29 | set(gcf, 'Color', 'w'); 30 | ``` 31 | 32 | Notice also that export_fig crops and anti-aliases (smooths, for bitmaps only) the output by default. However, these options can be disabled; see the Tips section below for details. 33 | 34 | **Resolution** - by default, export_fig exports bitmaps at screen resolution. However, you may wish to save them at a different resolution. You can do this using either of two options: `-m`, where is a positive real number, magnifies the figure by the factor for export, e.g. `-m2` produces an image double the size (in pixels) of the on screen figure; `-r`, again where is a positive real number, specifies the output bitmap to have pixels per inch, the dimensions of the figure (in inches) being those of the on screen figure. For example, using: 35 | ```Matlab 36 | export_fig test.png -m2.5 37 | ``` 38 | on the figure from the example above generates: 39 | 40 | ![](https://farm4.staticflickr.com/3937/15591910915_dc7040c477_o_d.png) 41 | 42 | Sometimes you might have a figure with an image in. For example: 43 | ```Matlab 44 | imshow(imread('cameraman.tif')) 45 | hold on 46 | plot(0:255, sin(linspace(0, 10, 256))*127+128); 47 | set(gcf, 'Position', [100 100 150 150]); 48 | ``` 49 | generates this figure: 50 | 51 | ![](https://farm4.staticflickr.com/3942/15589249581_ff87a56a3f_o_d.png) 52 | 53 | Here the image is displayed in the figure at resolution lower than its native resolution. However, you might want to export the figure at a resolution such that the image is output at its native (i.e. original) size (in pixels). Ordinarily this would require some non-trivial computation to work out what that resolution should be, but export_fig has an option to do this for you. Using: 54 | ```Matlab 55 | export_fig test.png -native 56 | ``` 57 | produces: 58 | 59 | ![](https://farm6.staticflickr.com/5604/15589249591_da2b2652e4_o_d.png) 60 | 61 | with the image being the size (in pixels) of the original image. Note that if you want an image to be a particular size, in pixels, in the output (other than its original size) then you can resize it to this size and use the `-native` option to achieve this. 62 | 63 | All resolution options (`-m`, `-q` and `-native`) correctly set the resolution information in PNG and TIFF files, as if the image were the dimensions of the on screen figure. 64 | 65 | **Shrinking dots & dashes** - when exporting figures with dashed or dotted lines using either the ZBuffer or OpenGL (default for bitmaps) renderers, the dots and dashes can appear much shorter, even non-existent, in the output file, especially if the lines are thick and/or the resolution is high. For example: 66 | ```Matlab 67 | plot(sin(linspace(0, 10, 1000)), 'b:', 'LineWidth', 4); 68 | hold on 69 | plot(cos(linspace(0, 7, 1000)), 'r--', 'LineWidth', 3); 70 | grid on 71 | export_fig test.png 72 | ``` 73 | generates: 74 | 75 | ![](https://farm4.staticflickr.com/3956/15592747732_f943d4aa0a_o_d.png) 76 | 77 | This problem can be overcome by using the painters renderer. For example: 78 | ```Matlab 79 | export_fig test.png -painters 80 | ``` 81 | used on the same figure generates: 82 | 83 | ![](https://farm4.staticflickr.com/3945/14971168504_77692f11f5_o_d.png) 84 | 85 | Note that not only are the plot lines correct, but the grid lines are too. 86 | 87 | **Transparency** - sometimes you might want a figure and axes' backgrounds to be transparent, so that you can see through them to a document (for example a presentation slide, with coloured or textured background) that the exported figure is placed in. To achieve this, first (optionally) set the axes' colour to 'none' prior to exporting, using: 88 | ```Matlab 89 | set(gca, 'Color', 'none'); % Sets axes background 90 | ``` 91 | 92 | then use export_fig's `-transparent` option when exporting: 93 | ```Matlab 94 | export_fig test.png -transparent 95 | ``` 96 | 97 | This will make the background transparent in PDF, EPS and PNG outputs. You can additionally save fully alpha-blended semi-transparent patch objects to the PNG format. For example: 98 | 99 | ```Matlab 100 | logo; 101 | alpha(0.5); 102 | ``` 103 | 104 | generates a figure like this: 105 | 106 | ![](https://farm4.staticflickr.com/3933/15405290339_b08de33528_o_d.png) 107 | 108 | If you then export this to PNG using the `-transparent` option you can then put the resulting image into, for example, a presentation slide with fancy, textured background, like so: 109 | 110 | ![](https://farm6.staticflickr.com/5599/15406302920_59beaefff1_o_d.png) 111 | 112 | and the image blends seamlessly with the background. 113 | 114 | **Image quality** - when publishing images of your results, you want them to look as good as possible. By default, when outputting to lossy file formats (PDF, EPS and JPEG), export_fig uses a high quality setting, i.e. low compression, for images, so little information is lost. This is in contrast to MATLAB's print and saveas functions, whose default quality settings are poor. For example: 115 | ```Matlab 116 | A = im2double(imread('peppers.png')); 117 | B = randn(ceil(size(A, 1)/6), ceil(size(A, 2)/6), 3) * 0.1; 118 | B = cat(3, kron(B(:,:,1), ones(6)), kron(B(:,:,2), ones(6)), kron(B(:,:,3), ones(6))); 119 | B = A + B(1:size(A, 1),1:size(A, 2),:); 120 | imshow(B); 121 | print -dpdf test.pdf 122 | ``` 123 | generates a PDF file, a sub-window of which looks (when zoomed in) like this: 124 | 125 | ![](https://farm6.staticflickr.com/5613/15405290309_881b2774d6_o_d.png) 126 | 127 | while the command 128 | 129 | ```Matlab 130 | export_fig test.pdf 131 | ``` 132 | on the same figure produces this: 133 | 134 | ![](https://farm4.staticflickr.com/3947/14971168174_687473133f_o_d.png) 135 | 136 | While much better, the image still contains some compression artifacts (see the low level noise around the edge of the pepper). You may prefer to export with no artifacts at all, i.e. lossless compression. Alternatively, you might need a smaller file, and be willing to accept more compression. Either way, export_fig has an option that can suit your needs: `-q`, where is a number from 0-100, will set the level of lossy image compression (again in PDF, EPS and JPEG outputs only; other formats are lossless), from high compression (0) to low compression/high quality (100). If you want lossless compression in any of those formats then specify a greater than 100. For example: 137 | ```Matlab 138 | export_fig test.pdf -q101 139 | ``` 140 | again on the same figure, produces this: 141 | 142 | ![](https://farm6.staticflickr.com/5608/15405803908_934512c1fe_o_d.png) 143 | 144 | Notice that all the noise has gone. 145 | 146 | ### Tips 147 | **Anti-aliasing** - the anti-aliasing which export_fig applies to bitmap outputs by default makes the images look nice, but it can also blur images and increase exporting time and memory requirements, so you might not always want it. You can set the level of anti-aliasing by using the `-a` option, where is 1 (no anti-aliasing), 2, 3 (default) or 4 (maximum anti-aliasing). 148 | 149 | **Cropping** - by default, export_fig crops its output to minimize the amount of empty space around the figure. If you'd prefer the figure to be uncropped, and instead have the same appearance (in terms of border width) as the on screen figure, then use the `-nocrop` option. 150 | 151 | **Colourspace** - by default, export_fig generates files in the RGB [colourspace](https://en.wikipedia.org/wiki/Color_space). However, you can also export in greyscale or the CMYK colourspace, using the `-grey` (or `-gray`) and `-cmyk` options respectively. The CMYK option is useful for publishers who require documents in this colourspace, but the option is only supported for PDF, EPS and TIFF files. 152 | 153 | **Specifying a target directory** - you can get export_fig to save output files to any directory (for which you have write permission), simply by specifying the full or relative path in the filename. For example: 154 | ```Matlab 155 | export_fig ../subdir/fig.png; 156 | export_fig('C:/Users/Me/Documents/figures/myfig', '-pdf', '-png'); 157 | ``` 158 | 159 | **Variable file names** - often you might want to save a series of figures in a for loop, each with a different name. For this you can use the functional form of input arguments, i.e. `export_fig(arg1, arg2)`, and construct the filename string in a variable. Here's an example of this: 160 | ```Matlab 161 | for a = 1:5 162 | plot(rand(5, 2)); 163 | export_fig(sprintf('plot%d.png', a)); 164 | end 165 | ``` 166 | When using the functional form like this, be sure to put string variables in quotes: 167 | ```Matlab 168 | export_fig(sprintf('plot%d', a), '-a1', '-pdf', '-png'); 169 | ``` 170 | 171 | **Specifying the figure/axes** - if you have mutiple figures open you can specify which figure to export using its handle: 172 | ```Matlab 173 | export_fig(figure_handle, filename); 174 | ``` 175 | Equally, if your figure contains several subplots then you can export just one of them by giving export_fig the handle to the relevant axes: 176 | ```Matlab 177 | export_fig(axes_handle, filename); 178 | ``` 179 | 180 | **Multiple formats** - save time by exporting to multiple formats simultaneously. E.g.: 181 | ```Matlab 182 | export_fig filename -pdf -eps -png -jpg -tiff 183 | ``` 184 | 185 | **Other file formats** - if you'd like to save your figure to a bitmap format that is not supported by export_fig, e.g. animated GIF, PPM file or a frame in a movie, then you can use export_fig to output the image, and optionally an alpha-matte, to the workspace. E.g.: 186 | ```Matlab 187 | frame = export_fig; 188 | ``` 189 | or 190 | ```Matlab 191 | [frame, alpha] = export_fig; 192 | ``` 193 | These variables can then be saved to other image formats using other functions, such as imwrite. 194 | 195 | **Appending to a file** - you can use the `-append` option to append the figure to the end of an image/document, if it already exists. This is supported for PDF and TIFF files only. Note that if you wish to append a lot of figures consecutively to a PDF, it can be more efficient to save all the figures to PDF separately then append them all in one go at the end (e.g. using [append_pdfs](http://www.mathworks.com/matlabcentral/fileexchange/31215-appendpdfs)). 196 | 197 | **Output to clipboard** - you can use the `-clipboard` option to copy the specified figure or axes to the system clipboard, for easy paste into other documents (e.g., Word or PowerPoint). Note that the image is copied in bitmap (not vector) format. 198 | 199 | **Font size** - if you want to place an exported figure in a document with the font a particular size then you need to set the font to that size in the figure, and not resize the output of export_fig in the document. To avoid resizing, simply make sure that the on screen figure is the size you want the output to be in the document before exporting. 200 | 201 | **Renderers** - MATLAB has three renderers for displaying and exporting figures: painters, OpenGL and ZBuffer. The different renderers have different [features](http://www.mathworks.com/access/helpdesk/help/techdoc/creating_plots/f3-84337.html#f3-102410), so if you aren't happy with the result from one renderer try another. By default, vector formats (i.e. PDF and EPS outputs) use the painters renderer, while other formats use the OpenGL renderer. Non-default renderers can be selected by using one of these three export_fig input options: `-painters`, `-opengl`, `-zbuffer`: 202 | ```Matlab 203 | export_fig test.png -painters 204 | ``` 205 | 206 | **Artifacts** - sometimes the output that you get from export_fig is not what you expected. If an output file contains artifacts that aren't in the on screen figure then make sure that the renderer used for rendering the figure on screen is the same as that used for exporting. To set the renderer used to display the figure, use: 207 | ```Matlab 208 | set(figure_handle, 'Renderer', 'opengl'); 209 | ``` 210 | After matching the two renderers, if the artifact appears in the on screen figure then you'll need to fix that before exporting. Alternatively you can try changing the renderer used by export_fig. Finally check that it isn't one of the known issues mentioned in the section below. 211 | 212 | **Smoothed/interpolated images in output PDF** - if you produce a PDF using export_fig and images in the PDF look overly smoothed or interpolated, this is because the software you are using to view the PDF is smoothing or interpolating the image data. The image is not smoothed in the PDF file itself. If the software has an option to disable this feature, you should select it. Alternatively, use another PDF viewer that doesn't exhibit this problem. 213 | 214 | **Locating Ghostscript/pdftops** - You may find a dialogue box appears when using export_fig, asking you to locate either [Ghostscript](http://www.ghostscript.com) or [pdftops](http://www.foolabs.com/xpdf). These are separate applications which export_fig requires to perform certain functions. If such a dialogue appears it is because export_fig can't find the application automatically. This is because you either haven't installed it, or it isn't in the normal place. Make sure you install the applications correctly first. They can be downloaded from the following places: 215 | 1. Ghostscript: [www.ghostscript.com](http://www.ghostscript.com) 216 | 2. pdftops (install the Xpdf package): [www.foolabs.com/xpdf](http://www.foolabs.com/xpdf) 217 | 218 | If you choose to install them in a non-default location then point export_fig 219 | to this location using the dialogue box. 220 | 221 | **Undefined function errors** - If you download and run export_fig and get an error similar to this: 222 | ``` 223 | ??? Undefined function or method 'print2array' for input arguments of type 'double'. 224 | ``` 225 | then you are missing one or more of the files that come in the export_fig package. Make sure that you click the "Get from GitHub" button at the top-right of the download [page](http://www.mathworks.co.uk/matlabcentral/fileexchange/23629-exportfig), then extract all the files in the zip file to the same directory. You should then have all the necessary files. 226 | 227 | ### Known issues 228 | There are lots of problems with MATLAB's exporting functions, especially `print`. Export_fig is simply a glorified wrapper for MATLAB's `print` function, and doesn't solve all of its bugs (yet?). Some of the problems I know about are: 229 | 230 | **Fonts** - when using the painters renderer, MATLAB can only export a small number of fonts, details of which can be found [here](http://www.mathworks.com/help/releases/R2014a/matlab/creating_plots/choosing-a-printer-driver.html#f3-96545). Export_fig attempts to correct font names in the resulting EPS file (up to a maximum of 11 different fonts in one figure), but this is not always guaranteed to work. In particular, the text positions will be affected. It also does not work for text blocks where the 'Interpreter' property is set to 'latex'. 231 | 232 | Also, when using the painters renderer, ghostscript will sometimes throw an error such as `Error: /undefined in /findfont`. This suggests that ghostscript could not find a definition file for one of your fonts. One possible fix for this is to make sure the file `EXPORT_FIG_PATH/.ignore/gs_font_path.txt` exists and contains a list of paths to the folder(s) containing the necessary font definitions (make sure that they are TrueType definitions!), separated by a semicolon. 233 | 234 | **RGB color data not yet supported in Painter's mode** - you will see this as a warning if you try to export a figure which contains patch objects whose face or vertex colors are specified as an RGB colour, rather than an index into the colormap, using the painters renderer (the default renderer for vector output). This problem can arise if you use `pcolor`, for example. This is a problem with MATLAB's painters renderer, which also affects `print`; there is currently no fix available in export_fig (other than to export to bitmap). The suggested workaround is to avoid colouring patches using RGB. First, try to use colours in the figure's colourmap (instructions [here](http://www.mathworks.co.uk/support/solutions/en/data/1-6OTPQE/)) - change the colourmap, if necessary. If you are using `pcolor`, try using [uimagesc](http://www.mathworks.com/matlabcentral/fileexchange/11368) (on the file exchange) instead. 235 | 236 | **Dashed contour lines appear solid** - when using the painters renderer, MATLAB cannot generate dashed lines using the `contour` function (either on screen or in exported PDF and EPS files). Details can be found [here](http://www.mathworks.com/support/solutions/en/data/1-14PPHB/?solution=1-14PPHB). 237 | 238 | **Text size** - when using the OpenGL or ZBuffer renderers, large text can be resized relative to the figure when exporting at non-screen-resolution (including using anti-alising at screen resolution). This is a feature of MATLAB's `print `function. In this case, try using the `-painters` option. 239 | 240 | **Lighting and transparency** - when using the painters renderer, transparency and lighting effects are not supported. Sorry, but this is an inherent feature of MATLAB's painters renderer. To find out more about the capabilities of each rendering method, see [here](http://www.mathworks.com/access/helpdesk/help/techdoc/creating_plots/f3-84337.html#f3-102410). You can still export transparent objects to vector format (SVG) using the excellent [plot2svg](http://www.mathworks.com/matlabcentral/fileexchange/7401) package, then convert this to PDF, for example using [Inkscape](http://inkscape.org/). However, it can't handle lighting. 241 | 242 | **Lines in patch objects** - when exporting patch objects to PDF using the painters renderer (default), sometimes the output can appear to have lines across the middle of rectangular patches; these lines are the colour of the background, as if there is a crack in the patch, allowing you to see through. This issue is a feature of the software used to display the PDF, rather than the PDF itself. Sometimes disabling anti-aliasing in this software can get rid of the lines ([discussion](https://github.com/altmany/export_fig/issues/44)). 243 | 244 | **Out of memory** - if you run into memory issues when using export_fig, some ways to get round this are: 245 | 1. Reduce the level of anti-aliasing. 246 | 2. Reduce the size of the figure. 247 | 3. Reduce the export resolution (dpi). 248 | 4. Change the renderer to painters or ZBuffer. 249 | 250 | **Errors** - the other common type of errors people get with export_fig are OpenGL errors. This isn't a fault of export_fig, but either a bug in MATLAB's `print`, or your graphics driver getting itself into a state. Always make sure your graphics driver is up-to-date. If it still doesn't work, try using the ZBuffer renderer. 251 | 252 | ### Raising issues 253 | If you think you have found a genuine error or issue with export_fig **that is not listed above**, first ensure that the figure looks correct on screen when rendered using the renderer that export_fig is set to use (e.g. if exporting to PDF or EPS, does the figure look correct on screen using the painters renderer, or if exporting to bitmap, does the figure look correct on screen using the OpenGL renderer?). If it looks wrong then the problem is there, and I cannot help (other than to suggest you try exporting using a different renderer). 254 | 255 | Secondly, if exporting to bitmap, do try all the renderers (i.e. try the options `-opengl`, `-zbuffer` and `-painters` separately), to see if one of them does produce an acceptable output, and if so, use that. 256 | 257 | If this still does not help, then ensure that you are using the latest version of export_fig, which is available [here](https://github.com/altmany/export_fig/archive/master.zip). 258 | 259 | If the figure looks correct on screen, but an error exists in the exported output (which cannot be solved using a different renderer) then please feel free to raise an [issue](https://github.com/altmany/export_fig/issues). Please be sure to include the .fig file, the export_fig command you use, the output you get, and a description of what you expected. I can't promise anything, but if it's easy to fix I may indeed do it. Often I will find that the error is due to a bug in MATLAB's `print` function, in which case I will suggest you submit it as a bug to TheMathWorks, and inform me of any fix they suggest. Also, if there's a feature you'd like that isn't supported please tell me what it is and I'll consider implementing it. 260 | 261 | ### And finally... 262 | 263 | ![](https://farm4.staticflickr.com/3956/15591911455_b9008bd77e_o_d.jpg) 264 | 265 | If you've ever wondered what's going on in the logo on the export_fig download page (reproduced here), then this explanantion is for you. The logo is designed to demonstrate as many of export_fig's features as possible: 266 | 267 | Given a figure containing a translucent mesh (top right), export_fig can export to pdf (bottom centre), which allows the figure to be zoomed-in without losing quality (because it's a vector graphic), but isn't able to reproduce the translucency. Also, depending on the PDF viewer program, small gaps appear between the patches, which are seen here as thin white lines. 268 | 269 | By contrast, when exporting to png (top left), translucency is preserved (see how the graphic below shows through), and the figure is anti-aliased. However, zooming-in does not reveal more detail since png is a bitmap format. Also, lines appear less sharp than in the pdf output. 270 | 271 | -------------------------------------------------------------------------------- /export_fig/append_pdfs.m: -------------------------------------------------------------------------------- 1 | %APPEND_PDFS Appends/concatenates multiple PDF files 2 | % 3 | % Example: 4 | % append_pdfs(output, input1, input2, ...) 5 | % append_pdfs(output, input_list{:}) 6 | % append_pdfs test.pdf temp1.pdf temp2.pdf 7 | % 8 | % This function appends multiple PDF files to an existing PDF file, or 9 | % concatenates them into a PDF file if the output file doesn't yet exist. 10 | % 11 | % This function requires that you have ghostscript installed on your 12 | % system. Ghostscript can be downloaded from: http://www.ghostscript.com 13 | % 14 | % IN: 15 | % output - string of output file name (including the extension, .pdf). 16 | % If it exists it is appended to; if not, it is created. 17 | % input1 - string of an input file name (including the extension, .pdf). 18 | % All input files are appended in order. 19 | % input_list - cell array list of input file name strings. All input 20 | % files are appended in order. 21 | 22 | % Copyright: Oliver Woodford, 2011 23 | 24 | % Thanks to Reinhard Knoll for pointing out that appending multiple pdfs in 25 | % one go is much faster than appending them one at a time. 26 | 27 | % Thanks to Michael Teo for reporting the issue of a too long command line. 28 | % Issue resolved on 5/5/2011, by passing gs a command file. 29 | 30 | % Thanks to Martin Wittmann for pointing out the quality issue when 31 | % appending multiple bitmaps. 32 | % Issue resolved (to best of my ability) 1/6/2011, using the prepress 33 | % setting 34 | 35 | % 26/02/15: If temp dir is not writable, use the output folder for temp 36 | % files when appending (Javier Paredes); sanity check of inputs 37 | 38 | function append_pdfs(varargin) 39 | 40 | if nargin < 2, return; end % sanity check 41 | 42 | % Are we appending or creating a new file 43 | append = exist(varargin{1}, 'file') == 2; 44 | output = [tempname '.pdf']; 45 | try 46 | % Ensure that the temp dir is writable (Javier Paredes 26/2/15) 47 | fid = fopen(output,'w'); 48 | fwrite(fid,1); 49 | fclose(fid); 50 | delete(output); 51 | isTempDirOk = true; 52 | catch 53 | % Temp dir is not writable, so use the output folder 54 | [dummy,fname,fext] = fileparts(output); %#ok 55 | fpath = fileparts(varargin{1}); 56 | output = fullfile(fpath,[fname fext]); 57 | isTempDirOk = false; 58 | end 59 | if ~append 60 | output = varargin{1}; 61 | varargin = varargin(2:end); 62 | end 63 | % Create the command file 64 | if isTempDirOk 65 | cmdfile = [tempname '.txt']; 66 | else 67 | cmdfile = fullfile(fpath,[fname '.txt']); 68 | end 69 | fh = fopen(cmdfile, 'w'); 70 | fprintf(fh, '-q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -dPDFSETTINGS=/prepress -sOutputFile="%s" -f', output); 71 | fprintf(fh, ' "%s"', varargin{:}); 72 | fclose(fh); 73 | % Call ghostscript 74 | ghostscript(['@"' cmdfile '"']); 75 | % Delete the command file 76 | delete(cmdfile); 77 | % Rename the file if needed 78 | if append 79 | movefile(output, varargin{1}); 80 | end 81 | end 82 | -------------------------------------------------------------------------------- /export_fig/copyfig.m: -------------------------------------------------------------------------------- 1 | function fh = copyfig(fh) 2 | %COPYFIG Create a copy of a figure, without changing the figure 3 | % 4 | % Examples: 5 | % fh_new = copyfig(fh_old) 6 | % 7 | % This function will create a copy of a figure, but not change the figure, 8 | % as copyobj sometimes does, e.g. by changing legends. 9 | % 10 | % IN: 11 | % fh_old - The handle of the figure to be copied. Default: gcf. 12 | % 13 | % OUT: 14 | % fh_new - The handle of the created figure. 15 | 16 | % Copyright (C) Oliver Woodford 2012 17 | 18 | % 26/02/15: If temp dir is not writable, use the dest folder for temp 19 | % destination files (Javier Paredes) 20 | % 15/04/15: Suppress warnings during copyobj (Dun Kirk comment on FEX page 2013-10-02) 21 | 22 | % Set the default 23 | if nargin == 0 24 | fh = gcf; 25 | end 26 | % Is there a legend? 27 | if isempty(findall(fh, 'Type', 'axes', 'Tag', 'legend')) 28 | % Safe to copy using copyobj 29 | oldWarn = warning('off'); %#ok %Suppress warnings during copyobj (Dun Kirk comment on FEX page 2013-10-02) 30 | fh = copyobj(fh, 0); 31 | warning(oldWarn); 32 | else 33 | % copyobj will change the figure, so save and then load it instead 34 | tmp_nam = [tempname '.fig']; 35 | try 36 | % Ensure that the temp dir is writable (Javier Paredes 26/2/15) 37 | fid = fopen(tmp_nam,'w'); 38 | fwrite(fid,1); 39 | fclose(fid); 40 | delete(tmp_nam); % cleanup 41 | catch 42 | % Temp dir is not writable, so use the current folder 43 | [dummy,fname,fext] = fileparts(tmp_nam); %#ok 44 | fpath = pwd; 45 | tmp_nam = fullfile(fpath,[fname fext]); 46 | end 47 | hgsave(fh, tmp_nam); 48 | fh = hgload(tmp_nam); 49 | delete(tmp_nam); 50 | end 51 | end 52 | -------------------------------------------------------------------------------- /export_fig/crop_borders.m: -------------------------------------------------------------------------------- 1 | function [A, vA, vB, bb_rel] = crop_borders(A, bcol, padding, crop_amounts) 2 | %CROP_BORDERS Crop the borders of an image or stack of images 3 | % 4 | % [B, vA, vB, bb_rel] = crop_borders(A, bcol, [padding]) 5 | % 6 | %IN: 7 | % A - HxWxCxN stack of images. 8 | % bcol - Cx1 background colour vector. 9 | % padding - scalar indicating how much padding to have in relation to 10 | % the cropped-image-size (0<=padding<=1). Default: 0 11 | % crop_amounts - 4-element vector of crop amounts: [top,right,bottom,left] 12 | % where NaN/Inf indicate auto-cropping, 0 means no cropping, 13 | % and any other value mean cropping in pixel amounts. 14 | % 15 | %OUT: 16 | % B - JxKxCxN cropped stack of images. 17 | % vA - coordinates in A that contain the cropped image 18 | % vB - coordinates in B where the cropped version of A is placed 19 | % bb_rel - relative bounding box (used for eps-cropping) 20 | 21 | %{ 22 | % 06/03/15: Improved image cropping thanks to Oscar Hartogensis 23 | % 08/06/15: Fixed issue #76: case of transparent figure bgcolor 24 | % 21/02/16: Enabled specifying non-automated crop amounts 25 | % 04/04/16: Fix per Luiz Carvalho for old Matlab releases 26 | %} 27 | 28 | if nargin < 3 29 | padding = 0; 30 | end 31 | if nargin < 4 32 | crop_amounts = nan(1,4); % =auto-cropping 33 | end 34 | crop_amounts(end+1:4) = NaN; % fill missing values with NaN 35 | 36 | [h, w, c, n] = size(A); 37 | if isempty(bcol) % case of transparent bgcolor 38 | bcol = A(ceil(end/2),1,:,1); 39 | end 40 | if isscalar(bcol) 41 | bcol = bcol(ones(c, 1)); 42 | end 43 | 44 | % Crop margin from left 45 | if ~isfinite(crop_amounts(4)) 46 | bail = false; 47 | for l = 1:w 48 | for a = 1:c 49 | if ~all(col(A(:,l,a,:)) == bcol(a)) 50 | bail = true; 51 | break; 52 | end 53 | end 54 | if bail 55 | break; 56 | end 57 | end 58 | else 59 | l = 1 + abs(crop_amounts(4)); 60 | end 61 | 62 | % Crop margin from right 63 | if ~isfinite(crop_amounts(2)) 64 | bcol = A(ceil(end/2),w,:,1); 65 | bail = false; 66 | for r = w:-1:l 67 | for a = 1:c 68 | if ~all(col(A(:,r,a,:)) == bcol(a)) 69 | bail = true; 70 | break; 71 | end 72 | end 73 | if bail 74 | break; 75 | end 76 | end 77 | else 78 | r = w - abs(crop_amounts(2)); 79 | end 80 | 81 | % Crop margin from top 82 | if ~isfinite(crop_amounts(1)) 83 | bcol = A(1,ceil(end/2),:,1); 84 | bail = false; 85 | for t = 1:h 86 | for a = 1:c 87 | if ~all(col(A(t,:,a,:)) == bcol(a)) 88 | bail = true; 89 | break; 90 | end 91 | end 92 | if bail 93 | break; 94 | end 95 | end 96 | else 97 | t = 1 + abs(crop_amounts(1)); 98 | end 99 | 100 | % Crop margin from bottom 101 | bcol = A(h,ceil(end/2),:,1); 102 | if ~isfinite(crop_amounts(3)) 103 | bail = false; 104 | for b = h:-1:t 105 | for a = 1:c 106 | if ~all(col(A(b,:,a,:)) == bcol(a)) 107 | bail = true; 108 | break; 109 | end 110 | end 111 | if bail 112 | break; 113 | end 114 | end 115 | else 116 | b = h - abs(crop_amounts(3)); 117 | end 118 | 119 | if padding == 0 % no padding 120 | if ~isequal([t b l r], [1 h 1 w]) % Check if we're actually croppping 121 | padding = 1; % Leave one boundary pixel to avoid bleeding on resize 122 | end 123 | elseif abs(padding) < 1 % pad value is a relative fraction of image size 124 | padding = sign(padding)*round(mean([b-t r-l])*abs(padding)); % ADJUST PADDING 125 | else % pad value is in units of 1/72" points 126 | padding = round(padding); % fix cases of non-integer pad value 127 | end 128 | 129 | if padding > 0 % extra padding 130 | % Create an empty image, containing the background color, that has the 131 | % cropped image size plus the padded border 132 | B = repmat(bcol,[(b-t)+1+padding*2,(r-l)+1+padding*2,1,n]); % Fix per Luiz Carvalho 133 | % vA - coordinates in A that contain the cropped image 134 | vA = [t b l r]; 135 | % vB - coordinates in B where the cropped version of A will be placed 136 | vB = [padding+1, (b-t)+1+padding, padding+1, (r-l)+1+padding]; 137 | % Place the original image in the empty image 138 | B(vB(1):vB(2), vB(3):vB(4), :, :) = A(vA(1):vA(2), vA(3):vA(4), :, :); 139 | A = B; 140 | else % extra cropping 141 | vA = [t-padding b+padding l-padding r+padding]; 142 | A = A(vA(1):vA(2), vA(3):vA(4), :, :); 143 | vB = [NaN NaN NaN NaN]; 144 | end 145 | 146 | % For EPS cropping, determine the relative BoundingBox - bb_rel 147 | bb_rel = [l-1 h-b-1 r+1 h-t+1]./[w h w h]; 148 | end 149 | 150 | function A = col(A) 151 | A = A(:); 152 | end 153 | -------------------------------------------------------------------------------- /export_fig/eps2pdf.m: -------------------------------------------------------------------------------- 1 | function eps2pdf(source, dest, crop, append, gray, quality, gs_options) 2 | %EPS2PDF Convert an eps file to pdf format using ghostscript 3 | % 4 | % Examples: 5 | % eps2pdf source dest 6 | % eps2pdf(source, dest, crop) 7 | % eps2pdf(source, dest, crop, append) 8 | % eps2pdf(source, dest, crop, append, gray) 9 | % eps2pdf(source, dest, crop, append, gray, quality) 10 | % eps2pdf(source, dest, crop, append, gray, quality, gs_options) 11 | % 12 | % This function converts an eps file to pdf format. The output can be 13 | % optionally cropped and also converted to grayscale. If the output pdf 14 | % file already exists then the eps file can optionally be appended as a new 15 | % page on the end of the eps file. The level of bitmap compression can also 16 | % optionally be set. 17 | % 18 | % This function requires that you have ghostscript installed on your 19 | % system. Ghostscript can be downloaded from: http://www.ghostscript.com 20 | % 21 | % Inputs: 22 | % source - filename of the source eps file to convert. The filename is 23 | % assumed to already have the extension ".eps". 24 | % dest - filename of the destination pdf file. The filename is assumed 25 | % to already have the extension ".pdf". 26 | % crop - boolean indicating whether to crop the borders off the pdf. 27 | % Default: true. 28 | % append - boolean indicating whether the eps should be appended to the 29 | % end of the pdf as a new page (if the pdf exists already). 30 | % Default: false. 31 | % gray - boolean indicating whether the output pdf should be grayscale 32 | % or not. Default: false. 33 | % quality - scalar indicating the level of image bitmap quality to 34 | % output. A larger value gives a higher quality. quality > 100 35 | % gives lossless output. Default: ghostscript prepress default. 36 | % gs_options - optional ghostscript options (e.g.: '-dNoOutputFonts'). If 37 | % multiple options are needed, enclose in call array: {'-a','-b'} 38 | 39 | % Copyright (C) Oliver Woodford 2009-2014, Yair Altman 2015- 40 | 41 | % Suggestion of appending pdf files provided by Matt C at: 42 | % http://www.mathworks.com/matlabcentral/fileexchange/23629 43 | 44 | % Thank you to Fabio Viola for pointing out compression artifacts, leading 45 | % to the quality setting. 46 | % Thank you to Scott for pointing out the subsampling of very small images, 47 | % which was fixed for lossless compression settings. 48 | 49 | % 9/12/2011 Pass font path to ghostscript. 50 | % 26/02/15: If temp dir is not writable, use the dest folder for temp 51 | % destination files (Javier Paredes) 52 | % 28/02/15: Enable users to specify optional ghostscript options (issue #36) 53 | % 01/03/15: Upon GS error, retry without the -sFONTPATH= option (this might solve 54 | % some /findfont errors according to James Rankin, FEX Comment 23/01/15) 55 | % 23/06/15: Added extra debug info in case of ghostscript error; code indentation 56 | % 04/10/15: Suggest a workaround for issue #41 (missing font path; thanks Mariia Fedotenkova) 57 | % 22/02/16: Bug fix from latest release of this file (workaround for issue #41) 58 | 59 | % Intialise the options string for ghostscript 60 | options = ['-q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -dPDFSETTINGS=/prepress -sOutputFile="' dest '"']; 61 | % Set crop option 62 | if nargin < 3 || crop 63 | options = [options ' -dEPSCrop']; 64 | end 65 | % Set the font path 66 | fp = font_path(); 67 | if ~isempty(fp) 68 | options = [options ' -sFONTPATH="' fp '"']; 69 | end 70 | % Set the grayscale option 71 | if nargin > 4 && gray 72 | options = [options ' -sColorConversionStrategy=Gray -dProcessColorModel=/DeviceGray']; 73 | end 74 | % Set the bitmap quality 75 | if nargin > 5 && ~isempty(quality) 76 | options = [options ' -dAutoFilterColorImages=false -dAutoFilterGrayImages=false']; 77 | if quality > 100 78 | options = [options ' -dColorImageFilter=/FlateEncode -dGrayImageFilter=/FlateEncode -c ".setpdfwrite << /ColorImageDownsampleThreshold 10 /GrayImageDownsampleThreshold 10 >> setdistillerparams"']; 79 | else 80 | options = [options ' -dColorImageFilter=/DCTEncode -dGrayImageFilter=/DCTEncode']; 81 | v = 1 + (quality < 80); 82 | quality = 1 - quality / 100; 83 | s = sprintf('<< /QFactor %.2f /Blend 1 /HSample [%d 1 1 %d] /VSample [%d 1 1 %d] >>', quality, v, v, v, v); 84 | options = sprintf('%s -c ".setpdfwrite << /ColorImageDict %s /GrayImageDict %s >> setdistillerparams"', options, s, s); 85 | end 86 | end 87 | % Enable users to specify optional ghostscript options (issue #36) 88 | if nargin > 6 && ~isempty(gs_options) 89 | if iscell(gs_options) 90 | gs_options = sprintf(' %s',gs_options{:}); 91 | elseif ~ischar(gs_options) 92 | error('gs_options input argument must be a string or cell-array of strings'); 93 | else 94 | gs_options = [' ' gs_options]; 95 | end 96 | options = [options gs_options]; 97 | end 98 | % Check if the output file exists 99 | if nargin > 3 && append && exist(dest, 'file') == 2 100 | % File exists - append current figure to the end 101 | tmp_nam = tempname; 102 | try 103 | % Ensure that the temp dir is writable (Javier Paredes 26/2/15) 104 | fid = fopen(tmp_nam,'w'); 105 | fwrite(fid,1); 106 | fclose(fid); 107 | delete(tmp_nam); 108 | catch 109 | % Temp dir is not writable, so use the dest folder 110 | [dummy,fname,fext] = fileparts(tmp_nam); %#ok 111 | fpath = fileparts(dest); 112 | tmp_nam = fullfile(fpath,[fname fext]); 113 | end 114 | % Copy the file 115 | copyfile(dest, tmp_nam); 116 | % Add the output file names 117 | options = [options ' -f "' tmp_nam '" "' source '"']; 118 | try 119 | % Convert to pdf using ghostscript 120 | [status, message] = ghostscript(options); 121 | catch me 122 | % Delete the intermediate file 123 | delete(tmp_nam); 124 | rethrow(me); 125 | end 126 | % Delete the intermediate file 127 | delete(tmp_nam); 128 | else 129 | % File doesn't exist or should be over-written 130 | % Add the output file names 131 | options = [options ' -f "' source '"']; 132 | % Convert to pdf using ghostscript 133 | [status, message] = ghostscript(options); 134 | end 135 | % Check for error 136 | if status 137 | % Retry without the -sFONTPATH= option (this might solve some GS 138 | % /findfont errors according to James Rankin, FEX Comment 23/01/15) 139 | orig_options = options; 140 | if ~isempty(fp) 141 | options = regexprep(options, ' -sFONTPATH=[^ ]+ ',' '); 142 | status = ghostscript(options); 143 | if ~status, return; end % hurray! (no error) 144 | end 145 | % Report error 146 | if isempty(message) 147 | error('Unable to generate pdf. Check destination directory is writable.'); 148 | elseif ~isempty(strfind(message,'/typecheck in /findfont')) 149 | % Suggest a workaround for issue #41 (missing font path) 150 | font_name = strtrim(regexprep(message,'.*Operand stack:\s*(.*)\s*Execution.*','$1')); 151 | fprintf(2, 'Ghostscript error: could not find the following font(s): %s\n', font_name); 152 | fpath = fileparts(mfilename('fullpath')); 153 | gs_fonts_file = fullfile(fpath, '.ignore', 'gs_font_path.txt'); 154 | fprintf(2, ' try to add the font''s folder to your %s file\n\n', gs_fonts_file); 155 | error('export_fig error'); 156 | else 157 | fprintf(2, '\nGhostscript error: perhaps %s is open by another application\n', dest); 158 | if ~isempty(gs_options) 159 | fprintf(2, ' or maybe the%s option(s) are not accepted by your GS version\n', gs_options); 160 | end 161 | fprintf(2, 'Ghostscript options: %s\n\n', orig_options); 162 | error(message); 163 | end 164 | end 165 | end 166 | 167 | % Function to return (and create, where necessary) the font path 168 | function fp = font_path() 169 | fp = user_string('gs_font_path'); 170 | if ~isempty(fp) 171 | return 172 | end 173 | % Create the path 174 | % Start with the default path 175 | fp = getenv('GS_FONTPATH'); 176 | % Add on the typical directories for a given OS 177 | if ispc 178 | if ~isempty(fp) 179 | fp = [fp ';']; 180 | end 181 | fp = [fp getenv('WINDIR') filesep 'Fonts']; 182 | else 183 | if ~isempty(fp) 184 | fp = [fp ':']; 185 | end 186 | fp = [fp '/usr/share/fonts:/usr/local/share/fonts:/usr/share/fonts/X11:/usr/local/share/fonts/X11:/usr/share/fonts/truetype:/usr/local/share/fonts/truetype']; 187 | end 188 | user_string('gs_font_path', fp); 189 | end 190 | -------------------------------------------------------------------------------- /export_fig/export_fig.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cthissen/Drex-MATLAB/39da9a38b1783c46fe4f2ac49e1c059e3c313b96/export_fig/export_fig.m -------------------------------------------------------------------------------- /export_fig/fix_lines.m: -------------------------------------------------------------------------------- 1 | %FIX_LINES Improves the line style of eps files generated by print 2 | % 3 | % Examples: 4 | % fix_lines fname 5 | % fix_lines fname fname2 6 | % fstrm_out = fixlines(fstrm_in) 7 | % 8 | % This function improves the style of lines in eps files generated by 9 | % MATLAB's print function, making them more similar to those seen on 10 | % screen. Grid lines are also changed from a dashed style to a dotted 11 | % style, for greater differentiation from dashed lines. 12 | % 13 | % The function also places embedded fonts after the postscript header, in 14 | % versions of MATLAB which place the fonts first (R2006b and earlier), in 15 | % order to allow programs such as Ghostscript to find the bounding box 16 | % information. 17 | % 18 | %IN: 19 | % fname - Name or path of source eps file. 20 | % fname2 - Name or path of destination eps file. Default: same as fname. 21 | % fstrm_in - File contents of a MATLAB-generated eps file. 22 | % 23 | %OUT: 24 | % fstrm_out - Contents of the eps file with line styles fixed. 25 | 26 | % Copyright: (C) Oliver Woodford, 2008-2014 27 | 28 | % The idea of editing the EPS file to change line styles comes from Jiro 29 | % Doke's FIXPSLINESTYLE (fex id: 17928) 30 | % The idea of changing dash length with line width came from comments on 31 | % fex id: 5743, but the implementation is mine :) 32 | 33 | % Thank you to Sylvain Favrot for bringing the embedded font/bounding box 34 | % interaction in older versions of MATLAB to my attention. 35 | % Thank you to D Ko for bringing an error with eps files with tiff previews 36 | % to my attention. 37 | % Thank you to Laurence K for suggesting the check to see if the file was 38 | % opened. 39 | 40 | % 01/03/15: Issue #20: warn users if using this function in HG2 (R2014b+) 41 | % 27/03/15: Fixed out of memory issue with enormous EPS files (generated by print() with OpenGL renderer), related to issue #39 42 | 43 | function fstrm = fix_lines(fstrm, fname2) 44 | 45 | % Issue #20: warn users if using this function in HG2 (R2014b+) 46 | if using_hg2 47 | warning('export_fig:hg2','The fix_lines function should not be used in this Matlab version.'); 48 | end 49 | 50 | if nargout == 0 || nargin > 1 51 | if nargin < 2 52 | % Overwrite the input file 53 | fname2 = fstrm; 54 | end 55 | % Read in the file 56 | fstrm = read_write_entire_textfile(fstrm); 57 | end 58 | 59 | % Move any embedded fonts after the postscript header 60 | if strcmp(fstrm(1:15), '%!PS-AdobeFont-') 61 | % Find the start and end of the header 62 | ind = regexp(fstrm, '[\n\r]%!PS-Adobe-'); 63 | [ind2, ind2] = regexp(fstrm, '[\n\r]%%EndComments[\n\r]+'); 64 | % Put the header first 65 | if ~isempty(ind) && ~isempty(ind2) && ind(1) < ind2(1) 66 | fstrm = fstrm([ind(1)+1:ind2(1) 1:ind(1) ind2(1)+1:end]); 67 | end 68 | end 69 | 70 | % Make sure all line width commands come before the line style definitions, 71 | % so that dash lengths can be based on the correct widths 72 | % Find all line style sections 73 | ind = [regexp(fstrm, '[\n\r]SO[\n\r]'),... % This needs to be here even though it doesn't have dots/dashes! 74 | regexp(fstrm, '[\n\r]DO[\n\r]'),... 75 | regexp(fstrm, '[\n\r]DA[\n\r]'),... 76 | regexp(fstrm, '[\n\r]DD[\n\r]')]; 77 | ind = sort(ind); 78 | % Find line width commands 79 | [ind2, ind3] = regexp(fstrm, '[\n\r]\d* w[\n\r]'); 80 | % Go through each line style section and swap with any line width commands 81 | % near by 82 | b = 1; 83 | m = numel(ind); 84 | n = numel(ind2); 85 | for a = 1:m 86 | % Go forwards width commands until we pass the current line style 87 | while b <= n && ind2(b) < ind(a) 88 | b = b + 1; 89 | end 90 | if b > n 91 | % No more width commands 92 | break; 93 | end 94 | % Check we haven't gone past another line style (including SO!) 95 | if a < m && ind2(b) > ind(a+1) 96 | continue; 97 | end 98 | % Are the commands close enough to be confident we can swap them? 99 | if (ind2(b) - ind(a)) > 8 100 | continue; 101 | end 102 | % Move the line style command below the line width command 103 | fstrm(ind(a)+1:ind3(b)) = [fstrm(ind(a)+4:ind3(b)) fstrm(ind(a)+1:ind(a)+3)]; 104 | b = b + 1; 105 | end 106 | 107 | % Find any grid line definitions and change to GR format 108 | % Find the DO sections again as they may have moved 109 | ind = int32(regexp(fstrm, '[\n\r]DO[\n\r]')); 110 | if ~isempty(ind) 111 | % Find all occurrences of what are believed to be axes and grid lines 112 | ind2 = int32(regexp(fstrm, '[\n\r] *\d* *\d* *mt *\d* *\d* *L[\n\r]')); 113 | if ~isempty(ind2) 114 | % Now see which DO sections come just before axes and grid lines 115 | ind2 = repmat(ind2', [1 numel(ind)]) - repmat(ind, [numel(ind2) 1]); 116 | ind2 = any(ind2 > 0 & ind2 < 12); % 12 chars seems about right 117 | ind = ind(ind2); 118 | % Change any regions we believe to be grid lines to GR 119 | fstrm(ind+1) = 'G'; 120 | fstrm(ind+2) = 'R'; 121 | end 122 | end 123 | 124 | % Define the new styles, including the new GR format 125 | % Dot and dash lengths have two parts: a constant amount plus a line width 126 | % variable amount. The constant amount comes after dpi2point, and the 127 | % variable amount comes after currentlinewidth. If you want to change 128 | % dot/dash lengths for a one particular line style only, edit the numbers 129 | % in the /DO (dotted lines), /DA (dashed lines), /DD (dot dash lines) and 130 | % /GR (grid lines) lines for the style you want to change. 131 | new_style = {'/dom { dpi2point 1 currentlinewidth 0.08 mul add mul mul } bdef',... % Dot length macro based on line width 132 | '/dam { dpi2point 2 currentlinewidth 0.04 mul add mul mul } bdef',... % Dash length macro based on line width 133 | '/SO { [] 0 setdash 0 setlinecap } bdef',... % Solid lines 134 | '/DO { [1 dom 1.2 dom] 0 setdash 0 setlinecap } bdef',... % Dotted lines 135 | '/DA { [4 dam 1.5 dam] 0 setdash 0 setlinecap } bdef',... % Dashed lines 136 | '/DD { [1 dom 1.2 dom 4 dam 1.2 dom] 0 setdash 0 setlinecap } bdef',... % Dot dash lines 137 | '/GR { [0 dpi2point mul 4 dpi2point mul] 0 setdash 1 setlinecap } bdef'}; % Grid lines - dot spacing remains constant 138 | 139 | % Construct the output 140 | % This is the original (memory-intensive) code: 141 | %first_sec = strfind(fstrm, '% line types:'); % Isolate line style definition section 142 | %[second_sec, remaining] = strtok(fstrm(first_sec+1:end), '/'); 143 | %[remaining, remaining] = strtok(remaining, '%'); 144 | %fstrm = [fstrm(1:first_sec) second_sec sprintf('%s\r', new_style{:}) remaining]; 145 | fstrm = regexprep(fstrm,'(% line types:.+?)/.+?%',['$1',sprintf('%s\r',new_style{:}),'%']); 146 | 147 | % Write the output file 148 | if nargout == 0 || nargin > 1 149 | read_write_entire_textfile(fname2, fstrm); 150 | end 151 | end 152 | -------------------------------------------------------------------------------- /export_fig/ghostscript.m: -------------------------------------------------------------------------------- 1 | function varargout = ghostscript(cmd) 2 | %GHOSTSCRIPT Calls a local GhostScript executable with the input command 3 | % 4 | % Example: 5 | % [status result] = ghostscript(cmd) 6 | % 7 | % Attempts to locate a ghostscript executable, finally asking the user to 8 | % specify the directory ghostcript was installed into. The resulting path 9 | % is stored for future reference. 10 | % 11 | % Once found, the executable is called with the input command string. 12 | % 13 | % This function requires that you have Ghostscript installed on your 14 | % system. You can download this from: http://www.ghostscript.com 15 | % 16 | % IN: 17 | % cmd - Command string to be passed into ghostscript. 18 | % 19 | % OUT: 20 | % status - 0 iff command ran without problem. 21 | % result - Output from ghostscript. 22 | 23 | % Copyright: Oliver Woodford, 2009-2015, Yair Altman 2015- 24 | %{ 25 | % Thanks to Jonas Dorn for the fix for the title of the uigetdir window on Mac OS. 26 | % Thanks to Nathan Childress for the fix to default location on 64-bit Windows systems. 27 | % 27/04/11 - Find 64-bit Ghostscript on Windows. Thanks to Paul Durack and 28 | % Shaun Kline for pointing out the issue 29 | % 04/05/11 - Thanks to David Chorlian for pointing out an alternative 30 | % location for gs on linux. 31 | % 12/12/12 - Add extra executable name on Windows. Thanks to Ratish 32 | % Punnoose for highlighting the issue. 33 | % 28/06/13 - Fix error using GS 9.07 in Linux. Many thanks to Jannick 34 | % Steinbring for proposing the fix. 35 | % 24/10/13 - Fix error using GS 9.07 in Linux. Many thanks to Johannes 36 | % for the fix. 37 | % 23/01/14 - Add full path to ghostscript.txt in warning. Thanks to Koen 38 | % Vermeer for raising the issue. 39 | % 27/02/15 - If Ghostscript croaks, display suggested workarounds 40 | % 30/03/15 - Improved performance by caching status of GS path check, if ok 41 | % 14/05/15 - Clarified warning message in case GS path could not be saved 42 | % 29/05/15 - Avoid cryptic error in case the ghostscipt path cannot be saved (issue #74) 43 | % 10/11/15 - Custom GS installation webpage for MacOS. Thanks to Andy Hueni via FEX 44 | %} 45 | 46 | try 47 | % Call ghostscript 48 | [varargout{1:nargout}] = system([gs_command(gs_path()) cmd]); 49 | catch err 50 | % Display possible workarounds for Ghostscript croaks 51 | url1 = 'https://github.com/altmany/export_fig/issues/12#issuecomment-61467998'; % issue #12 52 | url2 = 'https://github.com/altmany/export_fig/issues/20#issuecomment-63826270'; % issue #20 53 | hg2_str = ''; if using_hg2, hg2_str = ' or Matlab R2014a'; end 54 | fprintf(2, 'Ghostscript error. Rolling back to GS 9.10%s may possibly solve this:\n * %s ',hg2_str,url1,url1); 55 | if using_hg2 56 | fprintf(2, '(GS 9.10)\n * %s (R2014a)',url2,url2); 57 | end 58 | fprintf('\n\n'); 59 | if ismac || isunix 60 | url3 = 'https://github.com/altmany/export_fig/issues/27'; % issue #27 61 | fprintf(2, 'Alternatively, this may possibly be due to a font path issue:\n * %s\n\n',url3,url3); 62 | % issue #20 63 | fpath = which(mfilename); 64 | if isempty(fpath), fpath = [mfilename('fullpath') '.m']; end 65 | fprintf(2, 'Alternatively, if you are using csh, modify shell_cmd from "export..." to "setenv ..."\nat the bottom of %s\n\n',fpath,fpath); 66 | end 67 | rethrow(err); 68 | end 69 | end 70 | 71 | function path_ = gs_path 72 | % Return a valid path 73 | % Start with the currently set path 74 | path_ = user_string('ghostscript'); 75 | % Check the path works 76 | if check_gs_path(path_) 77 | return 78 | end 79 | % Check whether the binary is on the path 80 | if ispc 81 | bin = {'gswin32c.exe', 'gswin64c.exe', 'gs'}; 82 | else 83 | bin = {'gs'}; 84 | end 85 | for a = 1:numel(bin) 86 | path_ = bin{a}; 87 | if check_store_gs_path(path_) 88 | return 89 | end 90 | end 91 | % Search the obvious places 92 | if ispc 93 | default_location = 'C:\Program Files\gs\'; 94 | dir_list = dir(default_location); 95 | if isempty(dir_list) 96 | default_location = 'C:\Program Files (x86)\gs\'; % Possible location on 64-bit systems 97 | dir_list = dir(default_location); 98 | end 99 | executable = {'\bin\gswin32c.exe', '\bin\gswin64c.exe'}; 100 | ver_num = 0; 101 | % If there are multiple versions, use the newest 102 | for a = 1:numel(dir_list) 103 | ver_num2 = sscanf(dir_list(a).name, 'gs%g'); 104 | if ~isempty(ver_num2) && ver_num2 > ver_num 105 | for b = 1:numel(executable) 106 | path2 = [default_location dir_list(a).name executable{b}]; 107 | if exist(path2, 'file') == 2 108 | path_ = path2; 109 | ver_num = ver_num2; 110 | end 111 | end 112 | end 113 | end 114 | if check_store_gs_path(path_) 115 | return 116 | end 117 | else 118 | executable = {'/usr/bin/gs', '/usr/local/bin/gs'}; 119 | for a = 1:numel(executable) 120 | path_ = executable{a}; 121 | if check_store_gs_path(path_) 122 | return 123 | end 124 | end 125 | end 126 | % Ask the user to enter the path 127 | while true 128 | if strncmp(computer, 'MAC', 3) % Is a Mac 129 | % Give separate warning as the uigetdir dialogue box doesn't have a 130 | % title 131 | uiwait(warndlg('Ghostscript not found. Please locate the program.')) 132 | end 133 | base = uigetdir('/', 'Ghostcript not found. Please locate the program.'); 134 | if isequal(base, 0) 135 | % User hit cancel or closed window 136 | break; 137 | end 138 | base = [base filesep]; %#ok 139 | bin_dir = {'', ['bin' filesep], ['lib' filesep]}; 140 | for a = 1:numel(bin_dir) 141 | for b = 1:numel(bin) 142 | path_ = [base bin_dir{a} bin{b}]; 143 | if exist(path_, 'file') == 2 144 | if check_store_gs_path(path_) 145 | return 146 | end 147 | end 148 | end 149 | end 150 | end 151 | if ismac 152 | error('Ghostscript not found. Have you installed it (http://pages.uoregon.edu/koch)?'); 153 | else 154 | error('Ghostscript not found. Have you installed it from www.ghostscript.com?'); 155 | end 156 | end 157 | 158 | function good = check_store_gs_path(path_) 159 | % Check the path is valid 160 | good = check_gs_path(path_); 161 | if ~good 162 | return 163 | end 164 | % Update the current default path to the path found 165 | if ~user_string('ghostscript', path_) 166 | filename = fullfile(fileparts(which('user_string.m')), '.ignore', 'ghostscript.txt'); 167 | warning('Path to ghostscript installation could not be saved in %s (perhaps a permissions issue). You can manually create this file and set its contents to %s, to improve performance in future invocations (this warning is safe to ignore).', filename, path_); 168 | return 169 | end 170 | end 171 | 172 | function good = check_gs_path(path_) 173 | persistent isOk 174 | if isempty(path_) 175 | isOk = false; 176 | elseif ~isequal(isOk,true) 177 | % Check whether the path is valid 178 | [status, message] = system([gs_command(path_) '-h']); %#ok 179 | isOk = status == 0; 180 | end 181 | good = isOk; 182 | end 183 | 184 | function cmd = gs_command(path_) 185 | % Initialize any required system calls before calling ghostscript 186 | % TODO: in Unix/Mac, find a way to determine whether to use "export" (bash) or "setenv" (csh/tcsh) 187 | shell_cmd = ''; 188 | if isunix 189 | shell_cmd = 'export LD_LIBRARY_PATH=""; '; % Avoids an error on Linux with GS 9.07 190 | end 191 | if ismac 192 | shell_cmd = 'export DYLD_LIBRARY_PATH=""; '; % Avoids an error on Mac with GS 9.07 193 | end 194 | % Construct the command string 195 | cmd = sprintf('%s"%s" ', shell_cmd, path_); 196 | end 197 | -------------------------------------------------------------------------------- /export_fig/im2gif.m: -------------------------------------------------------------------------------- 1 | %IM2GIF Convert a multiframe image to an animated GIF file 2 | % 3 | % Examples: 4 | % im2gif infile 5 | % im2gif infile outfile 6 | % im2gif(A, outfile) 7 | % im2gif(..., '-nocrop') 8 | % im2gif(..., '-nodither') 9 | % im2gif(..., '-ncolors', n) 10 | % im2gif(..., '-loops', n) 11 | % im2gif(..., '-delay', n) 12 | % 13 | % This function converts a multiframe image to an animated GIF. 14 | % 15 | % To create an animation from a series of figures, export to a multiframe 16 | % TIFF file using export_fig, then convert to a GIF, as follows: 17 | % 18 | % for a = 2 .^ (3:6) 19 | % peaks(a); 20 | % export_fig test.tif -nocrop -append 21 | % end 22 | % im2gif('test.tif', '-delay', 0.5); 23 | % 24 | %IN: 25 | % infile - string containing the name of the input image. 26 | % outfile - string containing the name of the output image (must have the 27 | % .gif extension). Default: infile, with .gif extension. 28 | % A - HxWxCxN array of input images, stacked along fourth dimension, to 29 | % be converted to gif. 30 | % -nocrop - option indicating that the borders of the output are not to 31 | % be cropped. 32 | % -nodither - option indicating that dithering is not to be used when 33 | % converting the image. 34 | % -ncolors - option pair, the value of which indicates the maximum number 35 | % of colors the GIF can have. This can also be a quantization 36 | % tolerance, between 0 and 1. Default/maximum: 256. 37 | % -loops - option pair, the value of which gives the number of times the 38 | % animation is to be looped. Default: 65535. 39 | % -delay - option pair, the value of which gives the time, in seconds, 40 | % between frames. Default: 1/15. 41 | 42 | % Copyright (C) Oliver Woodford 2011 43 | 44 | function im2gif(A, varargin) 45 | 46 | % Parse the input arguments 47 | [A, options] = parse_args(A, varargin{:}); 48 | 49 | if options.crop ~= 0 50 | % Crop 51 | A = crop_borders(A, A(ceil(end/2),1,:,1)); 52 | end 53 | 54 | % Convert to indexed image 55 | [h, w, c, n] = size(A); 56 | A = reshape(permute(A, [1 2 4 3]), h, w*n, c); 57 | map = unique(reshape(A, h*w*n, c), 'rows'); 58 | if size(map, 1) > 256 59 | dither_str = {'dither', 'nodither'}; 60 | dither_str = dither_str{1+(options.dither==0)}; 61 | if options.ncolors <= 1 62 | [B, map] = rgb2ind(A, options.ncolors, dither_str); 63 | if size(map, 1) > 256 64 | [B, map] = rgb2ind(A, 256, dither_str); 65 | end 66 | else 67 | [B, map] = rgb2ind(A, min(round(options.ncolors), 256), dither_str); 68 | end 69 | else 70 | if max(map(:)) > 1 71 | map = double(map) / 255; 72 | A = double(A) / 255; 73 | end 74 | B = rgb2ind(im2double(A), map); 75 | end 76 | B = reshape(B, h, w, 1, n); 77 | 78 | % Bug fix to rgb2ind 79 | map(B(1)+1,:) = im2double(A(1,1,:)); 80 | 81 | % Save as a gif 82 | imwrite(B, map, options.outfile, 'LoopCount', round(options.loops(1)), 'DelayTime', options.delay); 83 | end 84 | 85 | %% Parse the input arguments 86 | function [A, options] = parse_args(A, varargin) 87 | % Set the defaults 88 | options = struct('outfile', '', ... 89 | 'dither', true, ... 90 | 'crop', true, ... 91 | 'ncolors', 256, ... 92 | 'loops', 65535, ... 93 | 'delay', 1/15); 94 | 95 | % Go through the arguments 96 | a = 0; 97 | n = numel(varargin); 98 | while a < n 99 | a = a + 1; 100 | if ischar(varargin{a}) && ~isempty(varargin{a}) 101 | if varargin{a}(1) == '-' 102 | opt = lower(varargin{a}(2:end)); 103 | switch opt 104 | case 'nocrop' 105 | options.crop = false; 106 | case 'nodither' 107 | options.dither = false; 108 | otherwise 109 | if ~isfield(options, opt) 110 | error('Option %s not recognized', varargin{a}); 111 | end 112 | a = a + 1; 113 | if ischar(varargin{a}) && ~ischar(options.(opt)) 114 | options.(opt) = str2double(varargin{a}); 115 | else 116 | options.(opt) = varargin{a}; 117 | end 118 | end 119 | else 120 | options.outfile = varargin{a}; 121 | end 122 | end 123 | end 124 | 125 | if isempty(options.outfile) 126 | if ~ischar(A) 127 | error('No output filename given.'); 128 | end 129 | % Generate the output filename from the input filename 130 | [path, outfile] = fileparts(A); 131 | options.outfile = fullfile(path, [outfile '.gif']); 132 | end 133 | 134 | if ischar(A) 135 | % Read in the image 136 | A = imread_rgb(A); 137 | end 138 | end 139 | 140 | %% Read image to uint8 rgb array 141 | function [A, alpha] = imread_rgb(name) 142 | % Get file info 143 | info = imfinfo(name); 144 | % Special case formats 145 | switch lower(info(1).Format) 146 | case 'gif' 147 | [A, map] = imread(name, 'frames', 'all'); 148 | if ~isempty(map) 149 | map = uint8(map * 256 - 0.5); % Convert to uint8 for storage 150 | A = reshape(map(uint32(A)+1,:), [size(A) size(map, 2)]); % Assume indexed from 0 151 | A = permute(A, [1 2 5 4 3]); 152 | end 153 | case {'tif', 'tiff'} 154 | A = cell(numel(info), 1); 155 | for a = 1:numel(A) 156 | [A{a}, map] = imread(name, 'Index', a, 'Info', info); 157 | if ~isempty(map) 158 | map = uint8(map * 256 - 0.5); % Convert to uint8 for storage 159 | A{a} = reshape(map(uint32(A{a})+1,:), [size(A) size(map, 2)]); % Assume indexed from 0 160 | end 161 | if size(A{a}, 3) == 4 162 | % TIFF in CMYK colourspace - convert to RGB 163 | if isfloat(A{a}) 164 | A{a} = A{a} * 255; 165 | else 166 | A{a} = single(A{a}); 167 | end 168 | A{a} = 255 - A{a}; 169 | A{a}(:,:,4) = A{a}(:,:,4) / 255; 170 | A{a} = uint8(A(:,:,1:3) .* A{a}(:,:,[4 4 4])); 171 | end 172 | end 173 | A = cat(4, A{:}); 174 | otherwise 175 | [A, map, alpha] = imread(name); 176 | A = A(:,:,:,1); % Keep only first frame of multi-frame files 177 | if ~isempty(map) 178 | map = uint8(map * 256 - 0.5); % Convert to uint8 for storage 179 | A = reshape(map(uint32(A)+1,:), [size(A) size(map, 2)]); % Assume indexed from 0 180 | elseif size(A, 3) == 4 181 | % Assume 4th channel is an alpha matte 182 | alpha = A(:,:,4); 183 | A = A(:,:,1:3); 184 | end 185 | end 186 | end 187 | -------------------------------------------------------------------------------- /export_fig/isolate_axes.m: -------------------------------------------------------------------------------- 1 | function fh = isolate_axes(ah, vis) 2 | %ISOLATE_AXES Isolate the specified axes in a figure on their own 3 | % 4 | % Examples: 5 | % fh = isolate_axes(ah) 6 | % fh = isolate_axes(ah, vis) 7 | % 8 | % This function will create a new figure containing the axes/uipanels 9 | % specified, and also their associated legends and colorbars. The objects 10 | % specified must all be in the same figure, but they will generally only be 11 | % a subset of the objects in the figure. 12 | % 13 | % IN: 14 | % ah - An array of axes and uipanel handles, which must come from the 15 | % same figure. 16 | % vis - A boolean indicating whether the new figure should be visible. 17 | % Default: false. 18 | % 19 | % OUT: 20 | % fh - The handle of the created figure. 21 | 22 | % Copyright (C) Oliver Woodford 2011-2013 23 | 24 | % Thank you to Rosella Blatt for reporting a bug to do with axes in GUIs 25 | % 16/03/12: Moved copyfig to its own function. Thanks to Bob Fratantonio 26 | % for pointing out that the function is also used in export_fig.m 27 | % 12/12/12: Add support for isolating uipanels. Thanks to michael for suggesting it 28 | % 08/10/13: Bug fix to allchildren suggested by Will Grant (many thanks!) 29 | % 05/12/13: Bug fix to axes having different units. Thanks to Remington Reid for reporting 30 | % 21/04/15: Bug fix for exporting uipanels with legend/colorbar on HG1 (reported by Alvaro 31 | % on FEX page as a comment on 24-Apr-2014); standardized indentation & help section 32 | % 22/04/15: Bug fix: legends and colorbars were not exported when exporting axes handle in HG2 33 | 34 | % Make sure we have an array of handles 35 | if ~all(ishandle(ah)) 36 | error('ah must be an array of handles'); 37 | end 38 | % Check that the handles are all for axes or uipanels, and are all in the same figure 39 | fh = ancestor(ah(1), 'figure'); 40 | nAx = numel(ah); 41 | for a = 1:nAx 42 | if ~ismember(get(ah(a), 'Type'), {'axes', 'uipanel'}) 43 | error('All handles must be axes or uipanel handles.'); 44 | end 45 | if ~isequal(ancestor(ah(a), 'figure'), fh) 46 | error('Axes must all come from the same figure.'); 47 | end 48 | end 49 | % Tag the objects so we can find them in the copy 50 | old_tag = get(ah, 'Tag'); 51 | if nAx == 1 52 | old_tag = {old_tag}; 53 | end 54 | set(ah, 'Tag', 'ObjectToCopy'); 55 | % Create a new figure exactly the same as the old one 56 | fh = copyfig(fh); %copyobj(fh, 0); 57 | if nargin < 2 || ~vis 58 | set(fh, 'Visible', 'off'); 59 | end 60 | % Reset the object tags 61 | for a = 1:nAx 62 | set(ah(a), 'Tag', old_tag{a}); 63 | end 64 | % Find the objects to save 65 | ah = findall(fh, 'Tag', 'ObjectToCopy'); 66 | if numel(ah) ~= nAx 67 | close(fh); 68 | error('Incorrect number of objects found.'); 69 | end 70 | % Set the axes tags to what they should be 71 | for a = 1:nAx 72 | set(ah(a), 'Tag', old_tag{a}); 73 | end 74 | % Keep any legends and colorbars which overlap the subplots 75 | % Note: in HG1 these are axes objects; in HG2 they are separate objects, therefore we 76 | % don't test for the type, only the tag (hopefully nobody but Matlab uses them!) 77 | lh = findall(fh, 'Tag', 'legend', '-or', 'Tag', 'Colorbar'); 78 | nLeg = numel(lh); 79 | if nLeg > 0 80 | set([ah(:); lh(:)], 'Units', 'normalized'); 81 | try 82 | ax_pos = get(ah, 'OuterPosition'); % axes and figures have the OuterPosition property 83 | catch 84 | ax_pos = get(ah, 'Position'); % uipanels only have Position, not OuterPosition 85 | end 86 | if nAx > 1 87 | ax_pos = cell2mat(ax_pos(:)); 88 | end 89 | ax_pos(:,3:4) = ax_pos(:,3:4) + ax_pos(:,1:2); 90 | try 91 | leg_pos = get(lh, 'OuterPosition'); 92 | catch 93 | leg_pos = get(lh, 'Position'); % No OuterPosition in HG2, only in HG1 94 | end 95 | if nLeg > 1; 96 | leg_pos = cell2mat(leg_pos); 97 | end 98 | leg_pos(:,3:4) = leg_pos(:,3:4) + leg_pos(:,1:2); 99 | ax_pos = shiftdim(ax_pos, -1); 100 | % Overlap test 101 | M = bsxfun(@lt, leg_pos(:,1), ax_pos(:,:,3)) & ... 102 | bsxfun(@lt, leg_pos(:,2), ax_pos(:,:,4)) & ... 103 | bsxfun(@gt, leg_pos(:,3), ax_pos(:,:,1)) & ... 104 | bsxfun(@gt, leg_pos(:,4), ax_pos(:,:,2)); 105 | ah = [ah; lh(any(M, 2))]; 106 | end 107 | % Get all the objects in the figure 108 | axs = findall(fh); 109 | % Delete everything except for the input objects and associated items 110 | delete(axs(~ismember(axs, [ah; allchildren(ah); allancestors(ah)]))); 111 | end 112 | 113 | function ah = allchildren(ah) 114 | ah = findall(ah); 115 | if iscell(ah) 116 | ah = cell2mat(ah); 117 | end 118 | ah = ah(:); 119 | end 120 | 121 | function ph = allancestors(ah) 122 | ph = []; 123 | for a = 1:numel(ah) 124 | h = get(ah(a), 'parent'); 125 | while h ~= 0 126 | ph = [ph; h]; 127 | h = get(h, 'parent'); 128 | end 129 | end 130 | end 131 | -------------------------------------------------------------------------------- /export_fig/pdf2eps.m: -------------------------------------------------------------------------------- 1 | %PDF2EPS Convert a pdf file to eps format using pdftops 2 | % 3 | % Examples: 4 | % pdf2eps source dest 5 | % 6 | % This function converts a pdf file to eps format. 7 | % 8 | % This function requires that you have pdftops, from the Xpdf suite of 9 | % functions, installed on your system. This can be downloaded from: 10 | % http://www.foolabs.com/xpdf 11 | % 12 | %IN: 13 | % source - filename of the source pdf file to convert. The filename is 14 | % assumed to already have the extension ".pdf". 15 | % dest - filename of the destination eps file. The filename is assumed to 16 | % already have the extension ".eps". 17 | 18 | % Copyright (C) Oliver Woodford 2009-2010 19 | 20 | % Thanks to Aldebaro Klautau for reporting a bug when saving to 21 | % non-existant directories. 22 | 23 | function pdf2eps(source, dest) 24 | % Construct the options string for pdftops 25 | options = ['-q -paper match -eps -level2 "' source '" "' dest '"']; 26 | % Convert to eps using pdftops 27 | [status, message] = pdftops(options); 28 | % Check for error 29 | if status 30 | % Report error 31 | if isempty(message) 32 | error('Unable to generate eps. Check destination directory is writable.'); 33 | else 34 | error(message); 35 | end 36 | end 37 | % Fix the DSC error created by pdftops 38 | fid = fopen(dest, 'r+'); 39 | if fid == -1 40 | % Cannot open the file 41 | return 42 | end 43 | fgetl(fid); % Get the first line 44 | str = fgetl(fid); % Get the second line 45 | if strcmp(str(1:min(13, end)), '% Produced by') 46 | fseek(fid, -numel(str)-1, 'cof'); 47 | fwrite(fid, '%'); % Turn ' ' into '%' 48 | end 49 | fclose(fid); 50 | end 51 | 52 | -------------------------------------------------------------------------------- /export_fig/pdftops.m: -------------------------------------------------------------------------------- 1 | function varargout = pdftops(cmd) 2 | %PDFTOPS Calls a local pdftops executable with the input command 3 | % 4 | % Example: 5 | % [status result] = pdftops(cmd) 6 | % 7 | % Attempts to locate a pdftops executable, finally asking the user to 8 | % specify the directory pdftops was installed into. The resulting path is 9 | % stored for future reference. 10 | % 11 | % Once found, the executable is called with the input command string. 12 | % 13 | % This function requires that you have pdftops (from the Xpdf package) 14 | % installed on your system. You can download this from: 15 | % http://www.foolabs.com/xpdf 16 | % 17 | % IN: 18 | % cmd - Command string to be passed into pdftops. 19 | % 20 | % OUT: 21 | % status - 0 iff command ran without problem. 22 | % result - Output from pdftops. 23 | 24 | % Copyright: Oliver Woodford, 2009-2010 25 | 26 | % Thanks to Jonas Dorn for the fix for the title of the uigetdir window on 27 | % Mac OS. 28 | % Thanks to Christoph Hertel for pointing out a bug in check_xpdf_path 29 | % under linux. 30 | % 23/01/2014 - Add full path to pdftops.txt in warning. 31 | % 27/05/2015 - Fixed alert in case of missing pdftops; fixed code indentation 32 | 33 | % Call pdftops 34 | [varargout{1:nargout}] = system(sprintf('"%s" %s', xpdf_path, cmd)); 35 | end 36 | 37 | function path_ = xpdf_path 38 | % Return a valid path 39 | % Start with the currently set path 40 | path_ = user_string('pdftops'); 41 | % Check the path works 42 | if check_xpdf_path(path_) 43 | return 44 | end 45 | % Check whether the binary is on the path 46 | if ispc 47 | bin = 'pdftops.exe'; 48 | else 49 | bin = 'pdftops'; 50 | end 51 | if check_store_xpdf_path(bin) 52 | path_ = bin; 53 | return 54 | end 55 | % Search the obvious places 56 | if ispc 57 | path_ = 'C:\Program Files\xpdf\pdftops.exe'; 58 | else 59 | path_ = '/usr/local/bin/pdftops'; 60 | end 61 | if check_store_xpdf_path(path_) 62 | return 63 | end 64 | % Ask the user to enter the path 65 | while 1 66 | errMsg = 'Pdftops not found. Please locate the program, or install xpdf-tools from '; 67 | url = 'http://foolabs.com/xpdf'; 68 | fprintf(2, '%s\n', [errMsg '' url '']); 69 | errMsg = [errMsg url]; %#ok 70 | if strncmp(computer,'MAC',3) % Is a Mac 71 | % Give separate warning as the MacOS uigetdir dialogue box doesn't have a title 72 | uiwait(warndlg(errMsg)) 73 | end 74 | base = uigetdir('/', errMsg); 75 | if isequal(base, 0) 76 | % User hit cancel or closed window 77 | break; 78 | end 79 | base = [base filesep]; %#ok 80 | bin_dir = {'', ['bin' filesep], ['lib' filesep]}; 81 | for a = 1:numel(bin_dir) 82 | path_ = [base bin_dir{a} bin]; 83 | if exist(path_, 'file') == 2 84 | break; 85 | end 86 | end 87 | if check_store_xpdf_path(path_) 88 | return 89 | end 90 | end 91 | error('pdftops executable not found.'); 92 | end 93 | 94 | function good = check_store_xpdf_path(path_) 95 | % Check the path is valid 96 | good = check_xpdf_path(path_); 97 | if ~good 98 | return 99 | end 100 | % Update the current default path to the path found 101 | if ~user_string('pdftops', path_) 102 | warning('Path to pdftops executable could not be saved. Enter it manually in %s.', fullfile(fileparts(which('user_string.m')), '.ignore', 'pdftops.txt')); 103 | return 104 | end 105 | end 106 | 107 | function good = check_xpdf_path(path_) 108 | % Check the path is valid 109 | [good, message] = system(sprintf('"%s" -h', path_)); %#ok 110 | % system returns good = 1 even when the command runs 111 | % Look for something distinct in the help text 112 | good = ~isempty(strfind(message, 'PostScript')); 113 | end 114 | -------------------------------------------------------------------------------- /export_fig/print2array.m: -------------------------------------------------------------------------------- 1 | function [A, bcol] = print2array(fig, res, renderer, gs_options) 2 | %PRINT2ARRAY Exports a figure to an image array 3 | % 4 | % Examples: 5 | % A = print2array 6 | % A = print2array(figure_handle) 7 | % A = print2array(figure_handle, resolution) 8 | % A = print2array(figure_handle, resolution, renderer) 9 | % A = print2array(figure_handle, resolution, renderer, gs_options) 10 | % [A bcol] = print2array(...) 11 | % 12 | % This function outputs a bitmap image of the given figure, at the desired 13 | % resolution. 14 | % 15 | % If renderer is '-painters' then ghostcript needs to be installed. This 16 | % can be downloaded from: http://www.ghostscript.com 17 | % 18 | % IN: 19 | % figure_handle - The handle of the figure to be exported. Default: gcf. 20 | % resolution - Resolution of the output, as a factor of screen 21 | % resolution. Default: 1. 22 | % renderer - string containing the renderer paramater to be passed to 23 | % print. Default: '-opengl'. 24 | % gs_options - optional ghostscript options (e.g.: '-dNoOutputFonts'). If 25 | % multiple options are needed, enclose in call array: {'-a','-b'} 26 | % 27 | % OUT: 28 | % A - MxNx3 uint8 image of the figure. 29 | % bcol - 1x3 uint8 vector of the background color 30 | 31 | % Copyright (C) Oliver Woodford 2008-2014, Yair Altman 2015- 32 | %{ 33 | % 05/09/11: Set EraseModes to normal when using opengl or zbuffer 34 | % renderers. Thanks to Pawel Kocieniewski for reporting the issue. 35 | % 21/09/11: Bug fix: unit8 -> uint8! Thanks to Tobias Lamour for reporting it. 36 | % 14/11/11: Bug fix: stop using hardcopy(), as it interfered with figure size 37 | % and erasemode settings. Makes it a bit slower, but more reliable. 38 | % Thanks to Phil Trinh and Meelis Lootus for reporting the issues. 39 | % 09/12/11: Pass font path to ghostscript. 40 | % 27/01/12: Bug fix affecting painters rendering tall figures. Thanks to 41 | % Ken Campbell for reporting it. 42 | % 03/04/12: Bug fix to median input. Thanks to Andy Matthews for reporting it. 43 | % 26/10/12: Set PaperOrientation to portrait. Thanks to Michael Watts for 44 | % reporting the issue. 45 | % 26/02/15: If temp dir is not writable, use the current folder for temp 46 | % EPS/TIF files (Javier Paredes) 47 | % 27/02/15: Display suggested workarounds to internal print() error (issue #16) 48 | % 28/02/15: Enable users to specify optional ghostscript options (issue #36) 49 | % 10/03/15: Fixed minor warning reported by Paul Soderlind; fixed code indentation 50 | % 28/05/15: Fixed issue #69: patches with LineWidth==0.75 appear wide (internal bug in Matlab's print() func) 51 | % 07/07/15: Fixed issue #83: use numeric handles in HG1 52 | %} 53 | 54 | % Generate default input arguments, if needed 55 | if nargin < 2 56 | res = 1; 57 | if nargin < 1 58 | fig = gcf; 59 | end 60 | end 61 | % Warn if output is large 62 | old_mode = get(fig, 'Units'); 63 | set(fig, 'Units', 'pixels'); 64 | px = get(fig, 'Position'); 65 | set(fig, 'Units', old_mode); 66 | npx = prod(px(3:4)*res)/1e6; 67 | if npx > 30 68 | % 30M pixels or larger! 69 | warning('MATLAB:LargeImage', 'print2array generating a %.1fM pixel image. This could be slow and might also cause memory problems.', npx); 70 | end 71 | % Retrieve the background colour 72 | bcol = get(fig, 'Color'); 73 | % Set the resolution parameter 74 | res_str = ['-r' num2str(ceil(get(0, 'ScreenPixelsPerInch')*res))]; 75 | % Generate temporary file name 76 | tmp_nam = [tempname '.tif']; 77 | try 78 | % Ensure that the temp dir is writable (Javier Paredes 26/2/15) 79 | fid = fopen(tmp_nam,'w'); 80 | fwrite(fid,1); 81 | fclose(fid); 82 | delete(tmp_nam); % cleanup 83 | isTempDirOk = true; 84 | catch 85 | % Temp dir is not writable, so use the current folder 86 | [dummy,fname,fext] = fileparts(tmp_nam); %#ok 87 | fpath = pwd; 88 | tmp_nam = fullfile(fpath,[fname fext]); 89 | isTempDirOk = false; 90 | end 91 | % Enable users to specify optional ghostscript options (issue #36) 92 | if nargin > 3 && ~isempty(gs_options) 93 | if iscell(gs_options) 94 | gs_options = sprintf(' %s',gs_options{:}); 95 | elseif ~ischar(gs_options) 96 | error('gs_options input argument must be a string or cell-array of strings'); 97 | else 98 | gs_options = [' ' gs_options]; 99 | end 100 | else 101 | gs_options = ''; 102 | end 103 | if nargin > 2 && strcmp(renderer, '-painters') 104 | % Print to eps file 105 | if isTempDirOk 106 | tmp_eps = [tempname '.eps']; 107 | else 108 | tmp_eps = fullfile(fpath,[fname '.eps']); 109 | end 110 | print2eps(tmp_eps, fig, 0, renderer, '-loose'); 111 | try 112 | % Initialize the command to export to tiff using ghostscript 113 | cmd_str = ['-dEPSCrop -q -dNOPAUSE -dBATCH ' res_str ' -sDEVICE=tiff24nc']; 114 | % Set the font path 115 | fp = font_path(); 116 | if ~isempty(fp) 117 | cmd_str = [cmd_str ' -sFONTPATH="' fp '"']; 118 | end 119 | % Add the filenames 120 | cmd_str = [cmd_str ' -sOutputFile="' tmp_nam '" "' tmp_eps '"' gs_options]; 121 | % Execute the ghostscript command 122 | ghostscript(cmd_str); 123 | catch me 124 | % Delete the intermediate file 125 | delete(tmp_eps); 126 | rethrow(me); 127 | end 128 | % Delete the intermediate file 129 | delete(tmp_eps); 130 | % Read in the generated bitmap 131 | A = imread(tmp_nam); 132 | % Delete the temporary bitmap file 133 | delete(tmp_nam); 134 | % Set border pixels to the correct colour 135 | if isequal(bcol, 'none') 136 | bcol = []; 137 | elseif isequal(bcol, [1 1 1]) 138 | bcol = uint8([255 255 255]); 139 | else 140 | for l = 1:size(A, 2) 141 | if ~all(reshape(A(:,l,:) == 255, [], 1)) 142 | break; 143 | end 144 | end 145 | for r = size(A, 2):-1:l 146 | if ~all(reshape(A(:,r,:) == 255, [], 1)) 147 | break; 148 | end 149 | end 150 | for t = 1:size(A, 1) 151 | if ~all(reshape(A(t,:,:) == 255, [], 1)) 152 | break; 153 | end 154 | end 155 | for b = size(A, 1):-1:t 156 | if ~all(reshape(A(b,:,:) == 255, [], 1)) 157 | break; 158 | end 159 | end 160 | bcol = uint8(median(single([reshape(A(:,[l r],:), [], size(A, 3)); reshape(A([t b],:,:), [], size(A, 3))]), 1)); 161 | for c = 1:size(A, 3) 162 | A(:,[1:l-1, r+1:end],c) = bcol(c); 163 | A([1:t-1, b+1:end],:,c) = bcol(c); 164 | end 165 | end 166 | else 167 | if nargin < 3 168 | renderer = '-opengl'; 169 | end 170 | err = false; 171 | % Set paper size 172 | old_pos_mode = get(fig, 'PaperPositionMode'); 173 | old_orientation = get(fig, 'PaperOrientation'); 174 | set(fig, 'PaperPositionMode', 'auto', 'PaperOrientation', 'portrait'); 175 | try 176 | % Workaround for issue #69: patches with LineWidth==0.75 appear wide (internal bug in Matlab's print() function) 177 | fp = []; % in case we get an error below 178 | fp = findall(fig, 'Type','patch', 'LineWidth',0.75); 179 | set(fp, 'LineWidth',0.5); 180 | % Fix issue #83: use numeric handles in HG1 181 | if ~using_hg2(fig), fig = double(fig); end 182 | % Print to tiff file 183 | print(fig, renderer, res_str, '-dtiff', tmp_nam); 184 | % Read in the printed file 185 | A = imread(tmp_nam); 186 | % Delete the temporary file 187 | delete(tmp_nam); 188 | catch ex 189 | err = true; 190 | end 191 | set(fp, 'LineWidth',0.75); % restore original figure appearance 192 | % Reset paper size 193 | set(fig, 'PaperPositionMode', old_pos_mode, 'PaperOrientation', old_orientation); 194 | % Throw any error that occurred 195 | if err 196 | % Display suggested workarounds to internal print() error (issue #16) 197 | fprintf(2, 'An error occured with Matlab''s builtin print function.\nTry setting the figure Renderer to ''painters'' or use opengl(''software'').\n\n'); 198 | rethrow(ex); 199 | end 200 | % Set the background color 201 | if isequal(bcol, 'none') 202 | bcol = []; 203 | else 204 | bcol = bcol * 255; 205 | if isequal(bcol, round(bcol)) 206 | bcol = uint8(bcol); 207 | else 208 | bcol = squeeze(A(1,1,:)); 209 | end 210 | end 211 | end 212 | % Check the output size is correct 213 | if isequal(res, round(res)) 214 | px = round([px([4 3])*res 3]); % round() to avoid an indexing warning below 215 | if ~isequal(size(A), px) 216 | % Correct the output size 217 | A = A(1:min(end,px(1)),1:min(end,px(2)),:); 218 | end 219 | end 220 | end 221 | 222 | % Function to return (and create, where necessary) the font path 223 | function fp = font_path() 224 | fp = user_string('gs_font_path'); 225 | if ~isempty(fp) 226 | return 227 | end 228 | % Create the path 229 | % Start with the default path 230 | fp = getenv('GS_FONTPATH'); 231 | % Add on the typical directories for a given OS 232 | if ispc 233 | if ~isempty(fp) 234 | fp = [fp ';']; 235 | end 236 | fp = [fp getenv('WINDIR') filesep 'Fonts']; 237 | else 238 | if ~isempty(fp) 239 | fp = [fp ':']; 240 | end 241 | fp = [fp '/usr/share/fonts:/usr/local/share/fonts:/usr/share/fonts/X11:/usr/local/share/fonts/X11:/usr/share/fonts/truetype:/usr/local/share/fonts/truetype']; 242 | end 243 | user_string('gs_font_path', fp); 244 | end 245 | -------------------------------------------------------------------------------- /export_fig/print2eps.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cthissen/Drex-MATLAB/39da9a38b1783c46fe4f2ac49e1c059e3c313b96/export_fig/print2eps.m -------------------------------------------------------------------------------- /export_fig/read_write_entire_textfile.m: -------------------------------------------------------------------------------- 1 | %READ_WRITE_ENTIRE_TEXTFILE Read or write a whole text file to/from memory 2 | % 3 | % Read or write an entire text file to/from memory, without leaving the 4 | % file open if an error occurs. 5 | % 6 | % Reading: 7 | % fstrm = read_write_entire_textfile(fname) 8 | % Writing: 9 | % read_write_entire_textfile(fname, fstrm) 10 | % 11 | %IN: 12 | % fname - Pathname of text file to be read in. 13 | % fstrm - String to be written to the file, including carriage returns. 14 | % 15 | %OUT: 16 | % fstrm - String read from the file. If an fstrm input is given the 17 | % output is the same as that input. 18 | 19 | function fstrm = read_write_entire_textfile(fname, fstrm) 20 | modes = {'rt', 'wt'}; 21 | writing = nargin > 1; 22 | fh = fopen(fname, modes{1+writing}); 23 | if fh == -1 24 | error('Unable to open file %s.', fname); 25 | end 26 | try 27 | if writing 28 | fwrite(fh, fstrm, 'char*1'); 29 | else 30 | fstrm = fread(fh, '*char')'; 31 | end 32 | catch ex 33 | fclose(fh); 34 | rethrow(ex); 35 | end 36 | fclose(fh); 37 | end 38 | -------------------------------------------------------------------------------- /export_fig/user_string.m: -------------------------------------------------------------------------------- 1 | function string = user_string(string_name, string) 2 | %USER_STRING Get/set a user specific string 3 | % 4 | % Examples: 5 | % string = user_string(string_name) 6 | % isSaved = user_string(string_name, new_string) 7 | % 8 | % Function to get and set a string in a system or user specific file. This 9 | % enables, for example, system specific paths to binaries to be saved. 10 | % 11 | % The specified string will be saved in a file named .txt, 12 | % either in a subfolder named .ignore under this file's folder, or in the 13 | % user's prefdir folder (in case this file's folder is non-writable). 14 | % 15 | % IN: 16 | % string_name - String containing the name of the string required, which 17 | % sets the filename storing the string: .txt 18 | % new_string - The new string to be saved in the .txt file 19 | % 20 | % OUT: 21 | % string - The currently saved string. Default: '' 22 | % isSaved - Boolean indicating whether the save was succesful 23 | 24 | % Copyright (C) Oliver Woodford 2011-2014, Yair Altman 2015- 25 | 26 | % This method of saving paths avoids changing .m files which might be in a 27 | % version control system. Instead it saves the user dependent paths in 28 | % separate files with a .txt extension, which need not be checked in to 29 | % the version control system. Thank you to Jonas Dorn for suggesting this 30 | % approach. 31 | 32 | % 10/01/2013 - Access files in text, not binary mode, as latter can cause 33 | % errors. Thanks to Christian for pointing this out. 34 | % 29/05/2015 - Save file in prefdir if current folder is non-writable (issue #74) 35 | 36 | if ~ischar(string_name) 37 | error('string_name must be a string.'); 38 | end 39 | % Create the full filename 40 | fname = [string_name '.txt']; 41 | dname = fullfile(fileparts(mfilename('fullpath')), '.ignore'); 42 | file_name = fullfile(dname, fname); 43 | if nargin > 1 44 | % Set string 45 | if ~ischar(string) 46 | error('new_string must be a string.'); 47 | end 48 | % Make sure the save directory exists 49 | %dname = fileparts(file_name); 50 | if ~exist(dname, 'dir') 51 | % Create the directory 52 | try 53 | if ~mkdir(dname) 54 | string = false; 55 | return 56 | end 57 | catch 58 | string = false; 59 | return 60 | end 61 | % Make it hidden 62 | try 63 | fileattrib(dname, '+h'); 64 | catch 65 | end 66 | end 67 | % Write the file 68 | fid = fopen(file_name, 'wt'); 69 | if fid == -1 70 | % file cannot be created/updated - use prefdir if file does not already exist 71 | % (if file exists but is simply not writable, don't create a duplicate in prefdir) 72 | if ~exist(file_name,'file') 73 | file_name = fullfile(prefdir, fname); 74 | fid = fopen(file_name, 'wt'); 75 | end 76 | if fid == -1 77 | string = false; 78 | return; 79 | end 80 | end 81 | try 82 | fprintf(fid, '%s', string); 83 | catch 84 | fclose(fid); 85 | string = false; 86 | return 87 | end 88 | fclose(fid); 89 | string = true; 90 | else 91 | % Get string 92 | fid = fopen(file_name, 'rt'); 93 | if fid == -1 94 | % file cannot be read, try to read the file in prefdir 95 | file_name = fullfile(prefdir, fname); 96 | fid = fopen(file_name, 'rt'); 97 | if fid == -1 98 | string = ''; 99 | return 100 | end 101 | end 102 | string = fgetl(fid); 103 | fclose(fid); 104 | end 105 | end 106 | -------------------------------------------------------------------------------- /export_fig/using_hg2.m: -------------------------------------------------------------------------------- 1 | %USING_HG2 Determine if the HG2 graphics engine is used 2 | % 3 | % tf = using_hg2(fig) 4 | % 5 | %IN: 6 | % fig - handle to the figure in question. 7 | % 8 | %OUT: 9 | % tf - boolean indicating whether the HG2 graphics engine is being used 10 | % (true) or not (false). 11 | 12 | % 19/06/2015 - Suppress warning in R2015b; cache result for improved performance 13 | 14 | function tf = using_hg2(fig) 15 | persistent tf_cached 16 | if isempty(tf_cached) 17 | try 18 | if nargin < 1, fig = figure('visible','off'); end 19 | oldWarn = warning('off','MATLAB:graphicsversion:GraphicsVersionRemoval'); 20 | try 21 | % This generates a [supressed] warning in R2015b: 22 | tf = ~graphicsversion(fig, 'handlegraphics'); 23 | catch 24 | tf = verLessThan('matlab','8.4'); % =R2014b 25 | end 26 | warning(oldWarn); 27 | catch 28 | tf = false; 29 | end 30 | if nargin < 1, delete(fig); end 31 | tf_cached = tf; 32 | else 33 | tf = tf_cached; 34 | end 35 | end 36 | -------------------------------------------------------------------------------- /functions/cmapscale.m: -------------------------------------------------------------------------------- 1 | function [colorRamp1,tics] = cmapscale(z,colorRamp0,varargin) 2 | % cmapscale does data-driven rescale of the color-ramp distribution 3 | % COLORRAMP1 = cmapscale(Z, COLORRAMP0) rescales COLORRAMP0 so that it matches 4 | % the cumulative distribution for the data Z. 5 | % 6 | % COLORRAMP1 = cmapscale(Z,COLORRAMP0,FACTOR) adjusts the contrast from 7 | % linear mapping (no change) when FACTOR = 0, to uniform mapping (maximum 8 | % contrast) when FACTOR = 1. The default is uniform mapping, which is 9 | % equivalent to histogram equalization. 10 | % 11 | % COLORRAMP1 = cmapscale(Z,COLORRAMP0,FACTOR,Z0) rescales so that the 12 | % value Z0 lies at the center of the color ramp (e.g. to center the color 13 | % ramp around zero). Default is no centering. 14 | % 15 | % [COLORRAMP1,TICS] = cmapscale(Z,COLORRAMP0,FACTOR,Z0,NTICS) returns an array 16 | % TICS, with size nTics x 2. The colorbar is more informative if it uses the 17 | % original color ramp. TICS are used to locate tics and tic labels relative 18 | % to COLORRAMP0. The default is no tics. The first column of TICS 19 | % has coordinates between 0 and 1 for the initial color ramp, and 20 | % the second column contains the respective Z values. 21 | % 22 | % By Mark Brandon, Yale University, August, 2012. 23 | % Inspired by Eisemann, M., Albuquerque, G., and Magnor, M., 2011, 24 | % Data driven color mapping: Proceedings EuroVA. 25 | % 26 | % 1-29-15. CJT. Modified calculation of tics to allow extrapolation (and 27 | % remove NaN by adding 'linear','extrap' to cLTics = interp1(). 28 | % 29 | % 3-13-15. CJT. Added a routine to check for two or fewer unique values in the 30 | % data Z and modify colorRamp1 and tics accordingly. 31 | % 32 | % 3-25-15. CJT. Added an addition varargin that allows the user to 33 | % set the limits on the colormap. For example, [0,1] sets the colormap 34 | % limits to 0 and 1. The default is empty, which sets the color limits 35 | % based on the data. 36 | %% Define default values and validate input arguments 37 | narginchk(2,6); % at least 2 but no more than 6 input arguments 38 | 39 | % Define default values 40 | factor = 1; % uniform mapping (maximum contrast) 41 | z0 = []; % no centering value 42 | nTics = []; % no set number of tics 43 | cLims = []; % let color limits be defined by data 44 | optargs = {factor, z0, nTics,cLims}; 45 | 46 | numvarargs = length(varargin); % number of variable input arguments 47 | optargs(1:numvarargs) = varargin; % transfer varargin into opt args 48 | [factor, z0, nTics, cLims] = optargs{:}; % parse varagin in into variables used later 49 | 50 | 51 | % Validate input arguments 52 | %... Check for contrast factor 53 | if factor<0 || factor>1 54 | error('Factor must be in the range 0 to 1.'); 55 | end 56 | 57 | %... Check for minimum number of unique z values 58 | nUnique = numel(unique(z(~isnan(z)))); 59 | if nUnique <= 2 60 | fprintf('cmapscale.m warning: Data values have < 3 unique values.\n'); 61 | end 62 | 63 | %... Check that centering value is within data range (or within cLims) 64 | if isempty(cLims) 65 | % check if z0 is between data 66 | if ~isempty(z0) && (z0 <= min(z(:)) || z0 >= max(z(:))) 67 | z0 = []; 68 | warning('Centering value z0 is outside range for data values in z. Resetting z0=[]'); 69 | end 70 | else 71 | % check if z0 is between color limits 72 | if ~isempty(z0) && (z0 <= cLims(1) || z0 >= cLims(2)) 73 | error('Centering value z0 is outside range for color limits.'); 74 | end 75 | end 76 | 77 | %... Check that nTics is a positive number 78 | validateattributes(nTics,{'numeric'},{'positive'},'cmapscale','nTics') 79 | 80 | %... Check that cLims make sense 81 | if ~isempty(cLims) 82 | validateattributes(cLims,{'numeric'},{'increasing','size',[1,2]},'cmapscale','cLims'); 83 | end 84 | %% Start Function 85 | %... Recast contrast factor as a stretching parameter s, and limit 86 | % its range to avoid numerical problems. 87 | s = tan(pi*factor/2); 88 | if s>1e4, 89 | s = 1e4; 90 | end 91 | 92 | %... Sort and normalize z to a linear scale cL, and a uniform scale cU 93 | if ~isempty(cLims) 94 | % set limits for colormap based on cmap inputs 95 | z = z(:); 96 | z = sort(z(~isnan(z(:)))); 97 | zMin = cLims(1); 98 | zMax = cLims(2); 99 | 100 | else 101 | % set limits for colormap based on data 102 | if nUnique > 1 103 | z = z(:); 104 | z = sort(z(~isnan(z(:)))); 105 | zMin = z(1); 106 | zMax = z(end); 107 | else 108 | z = z(~isnan(z(:))); 109 | zMin = mean(z(~isnan(z(:))))-1e-7; 110 | zMax = zMin + 2e-7; 111 | end 112 | end 113 | 114 | %... Limit the size of the distribution to 1000 (to avoid memory problems) 115 | if length(z) > 1000 116 | z = z(round((0:1/999:1)*(length(z)-1))+1); 117 | end 118 | cL = (z-zMin)/(zMax-zMin); 119 | m=size(cL,1); 120 | cU=(0:m-1)'./(m-1); 121 | 122 | %... Rounding to 1e-7, which ensures dynamic range but avoids round off problems 123 | cL = round(cL*1e7)*1e-7; 124 | 125 | %... Create a new color scale cS using weighted sum of cL and cU 126 | if isempty(z0) 127 | %... Color scale with no specified center point 128 | cS = (cL + s^2*cU)./(1 + s^2); 129 | else 130 | %... Color scale with specified center point 131 | i0 = sum(z(:)<=z0); 132 | if i0 == numel(z); 133 | warning('cmapscale.m: defined center value is greater than all data values'); 134 | i0 = i0-1; 135 | end 136 | if z(i0)==z0 137 | %... Center point matches existing value in z 138 | cL0 = cL(i0); 139 | cU0 = cU(i0); 140 | else 141 | %... Center point lies between values in z 142 | cL0 = (z0-zMin)/(zMax-zMin); 143 | cL = [cL(1:i0); cL0; cL(i0+1:m)]; 144 | cU0 = cU(i0) + (cU(i0+1) - cU(i0))/2; 145 | cU = [cU(1:i0); cU0; cU(i0+1:m)]; 146 | i0 = i0 + 1; 147 | m = m + 1; 148 | end 149 | %... Project the lower and upper halves of the data distributions onto the 150 | % new scale c1. This is done in two steps to maintain z0 at the center. 151 | % Project lower half 152 | cS = zeros(m,1); 153 | cS(1:i0) = 0.5*(cL(1:i0)/cL0 + s^2*cU(1:i0)/cU0)/(1 + s^2); 154 | cS0 = cS(i0); 155 | % Project upper half 156 | cS(i0:m) = cS0 + (1-cS0)* ... 157 | (cL(i0:m)/(1-cL0) + s^2*(cU(i0:m)-cU0)/(1-cU0))/(1 + s^2); 158 | end 159 | 160 | 161 | %... Remove duplicates in the z sequence (and cL sequence as well). 162 | % Each set of duplicates is reduced to a single value in the cL sequence, 163 | % and the average value in the cS sequence. The result is a strictly 164 | % monotonic sequence, which is required when using interp1 for 165 | % interpolation. 166 | % Create the adjaceny matrix A for z 167 | A = true(m,m); 168 | for i = 1:m 169 | A(i,:) = (cL==cL(i)); 170 | end 171 | % Calculate means for duplicate sequences 172 | w = sum(A,2); 173 | cL = (A*cL)./w; 174 | cS = (A*cS)./w; 175 | clear A 176 | % Consolidate into a unique sequence 177 | [cL,ia,~] = unique(cL); 178 | cS = cS(ia); 179 | m=size(cL,1); 180 | 181 | if nUnique > 1 182 | 183 | % Normalize to account for round-off errors 184 | cL = cL/cL(m); 185 | cS = cS/cS(m); 186 | %... Interpolate new colors for color ramp 187 | mRamp = size(colorRamp0,1); 188 | cLRamp = (0:mRamp-1)'/(mRamp-1); 189 | cSRamp = interp1(cL,cS,cLRamp); 190 | colorRamp1 = interp1(cLRamp,colorRamp0,cSRamp); 191 | colorRamp1 = round(colorRamp1.*1e7)*1e-7; 192 | 193 | %... Calculate tick values 194 | if ~isempty(nTics) && nTics~=0 195 | cSTics = (0:nTics-1)'/(nTics-1); 196 | cLTics = interp1(cS,cL,cSTics,'linear','extrap'); 197 | zTics = zMin + cLTics*(zMax-zMin); 198 | tics = [cSTics,zTics]; 199 | end 200 | else 201 | % we don't want to normalize if there is only 1 value 202 | mRamp = size(colorRamp0,1); 203 | cLRamp = (0:mRamp-1)'/(mRamp-1); 204 | colorRamp1 = interp1(cLRamp,colorRamp0,cS); 205 | 206 | if ~isempty(nTics) && nTics~=0 207 | cSTics = (0:nTics-1)'/(nTics-1); 208 | cLTics = cL*ones(nTics,1); 209 | zTics = zMin + cLTics*(zMax-zMin); 210 | tics = [cSTics,zTics]; 211 | 212 | end 213 | end 214 | 215 | 216 | 217 | 218 | end 219 | -------------------------------------------------------------------------------- /functions/euler2orientationmatrix.m: -------------------------------------------------------------------------------- 1 | function [g] = euler2orientationmatrix(eulerAngles) 2 | % Euler2Rotation inputs a set of 3 Euler angles (alpha beta and gamma) and outputs 3 | % a rotation matrix using the Bunge convention, (e.g. ZXZ, passive 4 | % intrinsic rotation). 5 | % 6 | % eulerAngles are input as radians 7 | 8 | %% Check inputs 9 | narginchk(1,1); 10 | 11 | % check eulerAngles is Nx3 12 | [~,nDim] = size(eulerAngles); 13 | if nDim ~= 3 14 | error('eulerAngles must be input as Nx3 matrix'); 15 | end 16 | 17 | % check range of eulerAngles 18 | maxE = max(eulerAngles,[],1); 19 | minE = min(eulerAngles,[],1); 20 | if any(maxE > 2*pi) || any(minE < 0) || maxE(2) > pi 21 | error('Expected euler angles be in range 0 < eulerAngles(:,1), eulerAngles(:,3) < 2pi and 0 < eulerAngles(:,2) < pi'); 22 | end 23 | 24 | % parse inputs 25 | Alpha = eulerAngles(:,1); % col vecs 26 | Beta = eulerAngles(:,2); 27 | Gamma = eulerAngles(:,3); 28 | 29 | %% Calculation 30 | c1 = cos(Alpha); 31 | s1 = sin(Alpha); 32 | 33 | c2 = cos(Beta); 34 | s2 = sin(Beta); 35 | 36 | c3 = cos(Gamma); 37 | s3 = sin(Gamma); 38 | 39 | % p 34 Engler and Randle, 2010 40 | %... Bunge convention (ZXZ), passive rotation 41 | g(:,1)= c1.*c3 - c2.*s1.*s3; %g11 42 | g(:,2)= c3.*s1 + c1.*c2.*s3; %g12 43 | g(:,3)= s2.*s3; %g13 44 | 45 | g(:,4)=-c1.*s3 - c2.*c3.*s1; %g21 46 | g(:,5)= c1.*c2.*c3 - s1.*s3; %g22 47 | g(:,6)= c3.*s2; %g23 48 | 49 | g(:,7)= s1.*s2; %g31 50 | g(:,8)=-c1.*s2; %g32 51 | g(:,9)= c2; %g33 52 | 53 | 54 | % % ... derivation 55 | % syms c1 s1 c2 s2 c3 s3 real 56 | % Ra = [c1 s1 0; 57 | % -s1 c1 0; 58 | % 0 0 1]; 59 | % 60 | % Rb = [1 0 0 ; 61 | % 0 c2 s2; 62 | % 0 -s2 c2]; 63 | % 64 | % Rg = [c3 s3 0; 65 | % -s3 c3 0; 66 | % 0 0 1]; 67 | % 68 | % R = Rg*Rb*Ra 69 | 70 | % Drexv2b.f90 71 | % acs0(i,1,1)=COS(phi2)*COS(phi1)-COS(theta)*SIN(phi1)*SIN(phi2) 72 | % acs0(i,1,2)=COS(phi2)*SIN(phi1)+COS(theta)*COS(phi1)*SIN(phi2) 73 | % acs0(i,1,3)=SIN(phi2)*SIN(theta) 74 | % 75 | % acs0(i,2,1)=-SIN(phi2)*COS(phi1)-COS(theta)*SIN(phi1)*COS(phi2) 76 | % acs0(i,2,2)=-SIN(phi2)*SIN(phi1)+COS(theta)*COS(phi1)*COS(phi2) 77 | % acs0(i,2,3)=COS(phi2)*SIN(theta) 78 | % 79 | % acs0(i,3,1)=SIN(theta)*SIN(phi1) 80 | % acs0(i,3,2)=-SIN(theta)*COS(phi1) 81 | % acs0(i,3,3)=COS(theta) 82 | 83 | end 84 | -------------------------------------------------------------------------------- /functions/gcolor.m: -------------------------------------------------------------------------------- 1 | function h = gcolor(varargin) 2 | %GCOLOR Pseudocolor (checkerboard) plot for grid-registered data. 3 | % GCOLOR(C) is a pseudocolor or "checkerboard" plot of matrix C, 4 | % where the values in C are centered on the grid nodes. 5 | % The values of the elements of C specify the color in each 6 | % cell of the plot. In the default shading mode, 'faceted', 7 | % each cell has a constant color and the last row and column of 8 | % C are not used. With shading('interp'), each cell has color 9 | % resulting from bilinear interpolation of the color at its 10 | % four vertices and all elements of C are used. 11 | % The smallest and largest elements of C are assigned the first and 12 | % last colors given in the color table; colors for the remainder of the 13 | % elements in C are determined by table-lookup within the remainder of 14 | % the color table. 15 | % 16 | % GCOLOR(X,Y,C), where X and Y are vectors or matrices, makes a 17 | % pseudocolor plot on the grid defined by X and Y. Values in 18 | % C correspond to the grid nodes indicated by X and Y. 19 | % 20 | % GCOLOR(AX,..) plots into AX instead of GCA. 21 | % 22 | % H = GCOLOR(...) returns a handle to a SURFACE object. 23 | % 24 | % GCOLOR is really a SURF with its view set to directly above. 25 | % 26 | % See also PCOLOR CAXIS, SURF, MESH, IMAGE, SHADING. 27 | 28 | %------------------------------- 29 | % Additional details: 30 | % 31 | % GCOLOR sets the View property of the SURFACE object to directly 32 | % overhead. 33 | % 34 | % If the NextPlot axis property is REPLACE (HOLD is off), GCOLOR resets 35 | % all axis properties, except Position, to their default values 36 | % and deletes all axis children (line, patch, surf, image, and 37 | % text objects). View is set to [0 90]. 38 | 39 | % Adapted from the Matlab GCOLOR program, which is covered 40 | % by the following copyright and revision number. 41 | % Copyright 1984-2006 The MathWorks, Inc. 42 | % $Revision: 5.9.4.6 $ $Date: 2011/07/25 03:49:30 $ 43 | % J.N. Little 1-5-92 44 | 45 | %% Start function 46 | % Parse possible Axes input 47 | [cax,args,nargs] = axescheck(varargin{:}); 48 | error(nargchk(1,3,nargs,'struct')) 49 | 50 | % do error checking before calling newplot. This argument checking should 51 | % match the surface(x,y,z) or surface(z) argument checking. 52 | if nargs == 2 53 | error(message('gcolor:InvalidNumberOfInputs')) 54 | end 55 | if isvector(args{end}) 56 | error(message('gcolor:NonMatrixColorInput')); 57 | end 58 | if nargs == 3 && LdimMismatch(args{1:3}) 59 | error(message('gcolor:InputSizeMismatch')); 60 | end 61 | for k = 1:nargs 62 | if ~isreal(args{k}) 63 | error(message('gcolor:NonRealInputs')); 64 | end 65 | end 66 | 67 | cax = newplot(cax); 68 | hold_state = ishold(cax); 69 | 70 | if nargs == 1 71 | x = args{1}; 72 | [m,n] = size(x); 73 | hh = surface(zeros(m+1,n+1),... 74 | padarray(c,[1 1],'replicate','post'), ... 75 | 'parent',cax); 76 | lims = [ 1 n 1 m]; 77 | elseif nargs == 3 78 | [x,y,c] = deal(args{1:3}); 79 | lims = [min(x(:)),max(x(:)),min(y(:)),max(y(:))]; 80 | [m,n] = size(c); 81 | dX = (x(1,end) - x(1,1))/(n-1); 82 | dY = (y(end,1) - y(1,1))/(m-1); 83 | xNew = x(1,1) - dX/2 : dX : x(1,end) + dX/2; 84 | yNew = (y(1,1) - dY/2 : dY : y(end,1) + dY/2)'; 85 | hh = surface(xNew,yNew,zeros(m+1,n+1), ... 86 | padarray(c,[1 1],'replicate','post'), ... 87 | 'parent',cax); 88 | end 89 | if ~hold_state 90 | set(cax,'View',[0 90]); 91 | set(cax,'Box','on'); 92 | axis(cax,lims); 93 | end 94 | if nargout == 1 95 | h = hh; 96 | end 97 | 98 | function ok = LdimMismatch(x,y,z) 99 | [xm,xn] = size(x); 100 | [ym,yn] = size(y); 101 | [zm,zn] = size(z); 102 | ok = (xm == 1 && xn ~= zn) || ... 103 | (xn == 1 && xm ~= zn) || ... 104 | (xm ~= 1 && xn ~= 1 && (xm ~= zm || xn ~= zn)) || ... 105 | (ym == 1 && yn ~= zm) || ... 106 | (yn == 1 && ym ~= zm) || ... 107 | (ym ~= 1 && yn ~= 1 && (ym ~= zm || yn ~= zn)); 108 | -------------------------------------------------------------------------------- /functions/lambertprojection.m: -------------------------------------------------------------------------------- 1 | function [LambertProj] = lambertprojection(spherePoints,varargin) 2 | % This function generates a set of approximately evenly spaced points on the 3 | % the upper (lower) hemisphere of a sphere. 4 | % The function starts with equally spaced points in an equal area 5 | % projection, and inverts the projection to get the 3D coordinates. 6 | % 7 | % The input spherePoints^2 is the total number of points in the equal area 8 | % projection. The actual points in the lower hemisphere of the stereonet 9 | % will be somewhat lower. 10 | % 11 | % The output variables are formatted to spherePoints x spherePoints 12 | % matrices 13 | % 14 | % 15 | %... Lower Hemisphere (default) 16 | % %%% %%% 17 | % %%% %%% 18 | % 19 | % %%% %%% 20 | % 21 | % %%% %%% 22 | % % +z +x 23 | % %%% %%% 24 | % 25 | % %%% %%% 26 | % 27 | % %%% %%% 28 | % 29 | % %%% +y %%% 30 | % 31 | % %... Upper Hemisphere 32 | % %%% +y %%% 33 | % %%% %%% 34 | % 35 | % %%% %%% 36 | % 37 | % %%% %%% 38 | % % +z +x 39 | % %%% %%% 40 | % 41 | % %%% %%% 42 | % 43 | % %%% %%% 44 | % 45 | % %%% %%% 46 | % 47 | 48 | %% Check Inputs 49 | narginchk(0,2); 50 | 51 | validateattributes(spherePoints,{'numeric'},{'scalar','>',0}) 52 | 53 | %% Begin Function 54 | 55 | % check for input 56 | if isempty(varargin) 57 | % set default lower hemisphere 58 | hemisphere = 'lower'; 59 | else 60 | hemisphere = varargin{1}; 61 | end 62 | 63 | 64 | %... build equal area projection 65 | R = sqrt(2); 66 | X = linspace(-R,R,spherePoints); 67 | Y = X; 68 | [X,Y] = meshgrid(X,Y); % X increases to right, 69 | Y = flipud(Y); % Y increases up 70 | 71 | %... calculate equivalent points in 3D 72 | x = sqrt(1-(X.^2 + Y.^2)/4).*X; 73 | switch hemisphere 74 | case 'lower' 75 | y = sqrt(1-(X.^2 + Y.^2)/4).* -Y; 76 | z = -(1 - (X.^2 + Y.^2)/2); 77 | 78 | case 'upper' 79 | y = sqrt(1-(X.^2 + Y.^2)/4).* Y; 80 | z = (1 - (X.^2 + Y.^2)/2); 81 | 82 | otherwise 83 | error('specify lower or upper for hemisphere'); 84 | end 85 | 86 | % correct roundoff errors 87 | x(1-(X.^2 + Y.^2)/4 < eps) = 0; 88 | y(1-(X.^2 + Y.^2)/4 < eps) = 0; 89 | 90 | % ensure unit vectors 91 | mag = sqrt(x.^2 + y.^2 + z.^2); 92 | x = x./mag; 93 | y = y./mag; 94 | z = z./mag; 95 | 96 | % parse output 97 | LambertProj.x = x; 98 | LambertProj.y = y; 99 | LambertProj.z = z; 100 | LambertProj.X = X; 101 | LambertProj.Y = Y; 102 | LambertProj.R = R; 103 | 104 | end 105 | 106 | -------------------------------------------------------------------------------- /functions/orientationmatrix2euler.m: -------------------------------------------------------------------------------- 1 | function [eulerAngles] = orientationmatrix2euler(g) 2 | % Calculate Euler angles from a given rotation matrix using Bunge 3 | % convention (passive, intrinsic ZXZ convention) 4 | % euler angles are returned in radians 5 | 6 | %% Check inputs 7 | narginchk(1,1); 8 | 9 | % g is given as Nx9 vector, see euler2rotationmatrix.m for details. 10 | validateattributes(g,{'numeric'},{'ndims',2,'ncols',9}); 11 | 12 | %% Begin function 13 | 14 | switch g(3,3) 15 | case -1 % Gimball lock, infinite solutions, set alpha = 0 16 | %... unclear how this affects crystal orientations 17 | %... Treat the singular case where beta = pi 18 | alpha = 0; 19 | beta = pi; 20 | gamma = atan2(R(1,2),R(1,1)); 21 | warning('Gimball Lock encountered, alpha and gamma are not unique') 22 | case 1 % Gimball lock, infinite solutions, set alpha = 0, 23 | %... Treat the singular case where beta = 0 24 | alpha = 0; 25 | beta = 0; 26 | gamma = atan2(R(1,2),R(1,1)); 27 | warning('Gimball Lock encountered, alpha and gamma are not unique') 28 | otherwise 29 | %... Treat the general case 30 | alpha = atan2(g(:,7),-g(:,8)); % atan2(g31,-g32) 31 | gamma = atan2(g(:,3), g(:,6)); % atan2(g13, g23) 32 | beta = atan2(sqrt(g(:,3).^2 + g(:,6).^2),g(:,9)); % atan2(sqrt(g13^2 + g23^2), g33) 33 | end 34 | 35 | %... adjust angles from [-pi,pi] as output by atan2 to [0,2pi] 36 | alpha = wrap(alpha,0,2*pi); 37 | beta = wrap(beta, 0,2*pi); 38 | gamma = wrap(gamma,0,2*pi); 39 | 40 | 41 | eulerAngles = [alpha beta gamma]; 42 | 43 | end 44 | 45 | -------------------------------------------------------------------------------- /functions/polenet.m: -------------------------------------------------------------------------------- 1 | function polenet(R,varargin) 2 | % plots background for polenet 3 | 4 | optArgs = {true}; % default is plot cross 5 | nArgsIn = find(~cellfun(@isempty,varargin)); 6 | optArgs(nArgsIn) = varargin(nArgsIn); 7 | [plotCross] = optArgs{:}; 8 | 9 | theta = (0:pi/180:2*pi); 10 | % R = 1; 11 | 12 | x = R*cos(theta); 13 | y = R*sin(theta); 14 | plot(x,y,'k-','LineWidth',1.5) 15 | hold on 16 | 17 | 18 | switch plotCross 19 | case true 20 | plot([0, 0], [-R, R],'k', [-R, R], [0, 0],'k'); 21 | plot([-R, R], [0, 0],'k', [0, 0], [-R, R],'k'); 22 | otherwise 23 | % don't plot cross 24 | end 25 | 26 | 27 | end -------------------------------------------------------------------------------- /functions/wrap.m: -------------------------------------------------------------------------------- 1 | function angle = wrap(angle, minAngle, span) 2 | %wrap Input angle is wrapped to [minAngle,minAngle+span]. 3 | % All angles should be given in either degrees or radians. 4 | % For example, minAngle = -pi/2 and span = pi would convert the input angle 5 | % to the interval -pi/2 to +pi/2. 6 | %% Calculation 7 | angle = angle - span.*floor((angle - minAngle)./span); 8 | end 9 | --------------------------------------------------------------------------------