-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFUN_Plot_irregular_grid_patch_2Dinput.m
More file actions
75 lines (49 loc) · 1.95 KB
/
FUN_Plot_irregular_grid_patch_2Dinput.m
File metadata and controls
75 lines (49 loc) · 1.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
function pid = FUN_Plot_irregular_grid_patch_2Dinput( lon, lat, data, varargin )
% FUN_Plot_patch_on_irregular_grid( lon, lat, data, varargin )
%
% INPUT
% lon [M x N]: it must be a 2-d variable
% lat [M x N]: it must be a 2-d variable
% data [M x N]: it must be a 2-d variable
%
% Output
% pid: figure handle
%
%
% V1.00 By L. Chi (L.Chi.Ocean@outlook.com)
%% Initialization
% ---- optional parameters ------------------------------------------------
is_rm_loadedd_param = true;
% facecolor in patch: ['flat'] | 'interp'
[facecolor, varargin] = FUN_codetools_read_from_varargin( varargin, 'facecolor', 'flat', is_rm_loadedd_param );
% linestyle in patch: ['none'] | '-' | '--' | ... (see linesytle in matlab help documents
[linestyle, varargin] = FUN_codetools_read_from_varargin( varargin, 'linestyle', 'none', is_rm_loadedd_param );
% if ~isempty( varargin )
% error('Unknown input paramters!');
% end
% ---- check --------------------------------------------------------------
if ~isvector(lon) && ~isvector(lat) && isequal( size(lon), size(lat) )
else
error('Input variables lon & lat must be 2-D variable sharing same size');
end
%% prepare temporal variables
IND = 1: numel(lon) ;
IND = reshape( IND, size(lon) );
nv1 = IND( 1:end-1, 1:end-1 );
nv2 = IND( 2:end, 1:end-1 );
nv3 = IND( 1:end-1, 2:end );
nv4 = IND( 2:end, 1:end-1 );
nv5 = IND( 2:end, 2:end );
nv6 = IND( 1:end-1, 2:end );
nv = [ [nv1(:) nv2(:) nv3(:)]; [ nv4(:) nv5(:) nv6(:) ] ];
loc = abs( lon(nv(:,1)) - lon(nv(:,2)) ) > 180 ;
loc = loc | abs( lon(nv(:,2)) - lon(nv(:,3)) ) > 180;
loc = loc | abs( lon(nv(:,1)) - lon(nv(:,3)) ) > 180;
nv(loc,:) = [];
vert = [lon(:) lat(:)];
%% plot by patch
if isempty( data )
pid = patch( 'Faces', nv, 'Vertices', vert, 'linestyle', linestyle, varargin{:} );
else
pid = patch( 'Faces', nv, 'Vertices', vert, 'FaceVertexCData', data(:), 'linestyle', linestyle, 'facecolor', facecolor, varargin{:} );
end