| 1 | %'decimate_arrows': plot 2D arrays of vector fields with color according to vector modulus, and save figures
|
|---|
| 2 | %------------------------------------------------------------------------
|
|---|
| 3 |
|
|---|
| 4 | %INPUT:
|
|---|
| 5 | % handles: Matlab structure containing all the information displayed in the GUI uvmat
|
|---|
| 6 |
|
|---|
| 7 | function decimate_arrows(handles)
|
|---|
| 8 | %------------------------------------------------------------------------
|
|---|
| 9 |
|
|---|
| 10 | %% get input data
|
|---|
| 11 | Data_uvmat=get(handles.uvmat,'UserData');
|
|---|
| 12 | Data=Data_uvmat.Field; %get the current plotted field
|
|---|
| 13 | requested=isfield(Data,'coord_x')&&isfield(Data,'coord_y')&&isfield(Data,'U')&&isfield(Data,'V')&&isfield(Data,'norm');
|
|---|
| 14 | if ~requested
|
|---|
| 15 | msgbox_uvmat('ERROR','unappropriate data: need vectors U, V on a regular grid')
|
|---|
| 16 | return
|
|---|
| 17 | end
|
|---|
| 18 | RootPath=get(handles.RootPath,'String');
|
|---|
| 19 | RootFile=get(handles.RootFile,'String');
|
|---|
| 20 | FileIndex=get(handles.FileIndex,'String');
|
|---|
| 21 |
|
|---|
| 22 | %% Calibration:
|
|---|
| 23 | % plot parameters
|
|---|
| 24 | nBits = 64;
|
|---|
| 25 | scale = 0.05;
|
|---|
| 26 | decimation = 8;
|
|---|
| 27 | % filtering procedure
|
|---|
| 28 | method = 'gaussian';
|
|---|
| 29 | window = 24;
|
|---|
| 30 |
|
|---|
| 31 | %% get colormap
|
|---|
| 32 | load('BuYlRd.mat','BuYlRd')
|
|---|
| 33 | BuYlRd = BuYlRd(1:floor(size(BuYlRd,1)/nBits):end,:);
|
|---|
| 34 |
|
|---|
| 35 | %% reduce the number of arrows
|
|---|
| 36 | x = Data.coord_x(1:decimation:end);
|
|---|
| 37 | y = Data.coord_y(1:decimation:end);
|
|---|
| 38 | [X,Y] = meshgrid(x,y);
|
|---|
| 39 | X=reshape(X,1,[]);
|
|---|
| 40 | Y=reshape(Y,1,[]);
|
|---|
| 41 | % Filtering data to take away spurious subsampling issues (see Shannon Theorem)
|
|---|
| 42 | filtU = smoothdata(Data.U,method,window,'omitnan');
|
|---|
| 43 | filtV = smoothdata(Data.V,method,window,'omitnan');
|
|---|
| 44 |
|
|---|
| 45 | U = reshape(filtU(1:decimation:end,1:decimation:end),1,[]);
|
|---|
| 46 | V = reshape(filtV(1:decimation:end,1:decimation:end),1,[]);
|
|---|
| 47 | S = sqrt(U.*U+V.*V);
|
|---|
| 48 | zmin = min(S);
|
|---|
| 49 | zmax = max(S);
|
|---|
| 50 | bins = linspace(zmin,zmax,nBits);
|
|---|
| 51 | plot_scale=sqrt((x(2)-x(1))*(y(2))-y(1));% typical distance between arrows
|
|---|
| 52 | scale_factor=plot_scale/zmax; % set the maximum arrow length to the typical distance between arrows
|
|---|
| 53 | U=scale_factor*U;
|
|---|
| 54 | V=scale_factor*V;
|
|---|
| 55 |
|
|---|
| 56 | %% plot size and position in the figure
|
|---|
| 57 | width = 6.75; % Width in inches
|
|---|
| 58 | height = 6; % Height in inches
|
|---|
| 59 | fsz = 12; % Fontsize
|
|---|
| 60 | lw = 1.25; % LineWidth
|
|---|
| 61 |
|
|---|
| 62 | %% make the plot
|
|---|
| 63 | figure(1)
|
|---|
| 64 | clf
|
|---|
| 65 | ax2 = axes('Visible','off','HandleVisibility','off');
|
|---|
| 66 | pos = get(1, 'Position');
|
|---|
| 67 | set(1, 'Position', [pos(1) pos(2) width*100, height*100]); %<- Set size
|
|---|
| 68 | set(ax2, 'FontSize', fsz, 'LineWidth', lw); %<- Set properties
|
|---|
| 69 | set(1, 'defaultTextInterpreter','latex');
|
|---|
| 70 | for i = 1:nBits-1
|
|---|
| 71 | ii=find((S - bins(i+1) <= 0).*(S - bins(i) > 0));
|
|---|
| 72 | quiver(X(ii),Y(ii),U(ii),V(ii),'off','Color',BuYlRd(i,:),'LineWidth',1.2,'MaxHeadSize',scale_factor*bins(i))
|
|---|
| 73 | hold on
|
|---|
| 74 | end
|
|---|
| 75 | %quiver(X,Y,U,V)
|
|---|
| 76 | cc=colorbar;
|
|---|
| 77 | set(cc,'TickLabelInterpreter','latex')
|
|---|
| 78 | cc.Label.String='cm/s';
|
|---|
| 79 | clim([zmin zmax])
|
|---|
| 80 | axis equal
|
|---|
| 81 | xlim([Data.coord_x(1),Data.coord_x(end)])
|
|---|
| 82 | ylim([Data.coord_y(1),Data.coord_y(end)])
|
|---|
| 83 | hold off
|
|---|
| 84 | xlabel('$x(cm)$')
|
|---|
| 85 | ylabel('$y(cm)$')
|
|---|
| 86 |
|
|---|
| 87 | %% Set the figure size
|
|---|
| 88 | set(1,'InvertHardcopy','on');
|
|---|
| 89 | set(1,'PaperUnits', 'centimeters');
|
|---|
| 90 | papersize = get(1, 'PaperSize');
|
|---|
| 91 | left = (papersize(1)- width)/2;
|
|---|
| 92 | bottom = (papersize(2)- height)/2;
|
|---|
| 93 | myfiguresize = [left, bottom, width, height];
|
|---|
| 94 | set(1,'PaperPosition', myfiguresize);
|
|---|
| 95 |
|
|---|
| 96 | %% Save the figure as a pdf file in the appropriate figure folder
|
|---|
| 97 | [pp,camera]=fileparts(RootPath);
|
|---|
| 98 | [ppp,exp]=fileparts(pp);
|
|---|
| 99 | FigPath=fullfile(fileparts(ppp),'0_FIG')
|
|---|
| 100 | if ~exist(FigPath,'dir')
|
|---|
| 101 | [s,msg]=mkdir(FigPath); %create the folder if it does not exist
|
|---|
| 102 | if s
|
|---|
| 103 | disp([FigPath ' created'])
|
|---|
| 104 | else
|
|---|
| 105 | msgbox_uvmat('ERROR',msg)
|
|---|
| 106 | return
|
|---|
| 107 | end
|
|---|
| 108 | end
|
|---|
| 109 | exppath = fullfile(FigPath,exp);
|
|---|
| 110 | if ~exist(exppath,'dir')
|
|---|
| 111 | [s,msg]=mkdir(exppath);%create the folder if it does not exist
|
|---|
| 112 | if s
|
|---|
| 113 | disp([exppath ' created'])
|
|---|
| 114 | else
|
|---|
| 115 | msgbox_uvmat('ERROR',msg)
|
|---|
| 116 | return
|
|---|
| 117 | end
|
|---|
| 118 | end
|
|---|
| 119 | camerapath=fullfile(exppath,camera);
|
|---|
| 120 | if ~exist(camerapath,'dir')
|
|---|
| 121 | [s,msg]=mkdir(camerapath);%create the folder if it does not exist
|
|---|
| 122 | if s
|
|---|
| 123 | disp([camerapath ' created'])
|
|---|
| 124 | else
|
|---|
| 125 | msgbox_uvmat('ERROR',msg)
|
|---|
| 126 | return
|
|---|
| 127 | end
|
|---|
| 128 | end
|
|---|
| 129 |
|
|---|
| 130 | outputname=fullfile(camerapath,[RootFile FileIndex '.pdf']);
|
|---|
| 131 | print(1,outputname,'-dpdf')
|
|---|
| 132 |
|
|---|
| 133 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|---|
| 134 |
|
|---|
| 135 |
|
|---|