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