-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmmpolar.m
1346 lines (1319 loc) · 54 KB
/
mmpolar.m
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
function out=mmpolar(varargin)
%MMPOLAR Polar Plot with Settable Properties.
% MMPOLAR(Theta,Rho) creates a polar coordinate plot using the angle Theta
% in RADIANS and radius in Rho. Rho can contain negative values.
% MMPOLAR(Theta,Rho,S) creates the plot using the line spec given by S. See
% the function PLOT for information about S.
% MMPOLAR(Theta1,Rho1,S1,Theta2,Rho2,S2,...) plots all the defined curves.
%
% MMPOLAR(Theta1,Rho1,S1,...,'PName',PValue,...) plots all defined curves,
% and sets plot property names to the corresponding property values.
% MMPOLAR(Theta1,Rho1,S1,...,P) plots all the defined curves, and uses the
% structure P having fieldnames equal to plot property names to set
% corresponding property values contained in the associated fields.
%
% H=MMPOLAR(Theta,Rho,...) returns handles to lines or lineseries objects.
% For example, set(H,'LineWidth',2) sets all linewidths to 2 points.
% Note: 'LineWidth' is NOT a property that can be set with MMPOLAR. It must
% be set as shown above by using the SET function on the line handles H.
%
% MMPOLAR('PName',PValue,...) sets the property names to the corresponding
% property values. See below for property name/value pairs. Just as with
% the function SET 'PName' is case insensitive and need only be unique.
% MMPOLAR with no input argument returns a structure with fieldnames equal
% to property names each containing the associated property values.
% MMPOLAR(P) sets property values using the structure P as described above.
% MMPOLAR('PName') returns the property value associated with 'PName'.
% MMPOLAR({'PName1','PName2',...}) returns multiple property values in a
% cell array.
% MMPOLAR(Hax,...) uses the axes having handle Hax.
%
% Examples: MMPOLAR(Theta,Rho,S,'Style','compass') creates a polar plot with
% theta=0 pointing North and theta increasing in the clockwise direction.
%
% MMPOLAR(Theta,Rho,S) creates a cartesian polar plot where theta=0 is along
% the x-axis and theta increases in the counterclockwise direction.
%
% MMPOLAR works with HOLD, XLABEL, YLABEL, TITLE, ZOOM, SUBPLOT
% but does not work with AXIS, GRID (Use MMPOLAR properties to set these)
%
% See also POLAR, PLOT, HOLD
%
% PROPERTY VALUE {Default} DESCRIPTION
% Style {cartesian} | compass shortcut to two common polar
% styles. Cartesian: theta=0 points east and increases
% going north. Compass: theta=0 points north and
% increases going east. See TDirection and TZeroDirection.
% Axis {on} | off shortcut for grids, ticks, border,
% backgroundcolor, visibility
% Border {on} | off shortcut for axis border, tick mark visibility.
% Grid {on} | off shortcut for visibility of rho and theta grids
% RLimit [Rmin Rmax] rho axis limits, may be negative values
% TLimit [Tmin Tmax] theta axis limits in RADIANS
% RTickUnits {''} string added to last rho tick label to denote units
% TTickScale {degrees} | radians theta axis tick label scaling
% TDirection cw | {ccw} direction of increasing theta
% TZeroDirection North | {East} | South | West theta=0 axis direction
%
% BackgroundColor {w} colorspec for axis background color
% BorderColor {k} colorspec for axis border and tick mark colors
% FontName string font name for tick labels
% FontSize scalar font size for tick labels
% FontWeight {normal} | bold font weight for tick labels
% TickLength {.02} normalized length of rho and theta axis tick marks
%
% RGridColor {k} colorspec for rho axis grid color
% RGridLineStyle - | -- | {:} | -. rho axis grid line style
% RGridLineWidth {0.5} rho axis grid line width in points
% RGridVisible {on} | off rho axis grid visibility
% RTickAngle [scalar] angular position of rho axis tick labels in
% TTickScale units
% RTickOffset {.04} Normalized radial offset for rho tick labels
% RTickLabel string cell array containing rho axis tick labels
% RTickLabelVisible {on} | off visibility of rho axis tick labels
% RTickLabelHalign {center} | left | right horizontal
% alignment of rho axis tick labels
% RTickLabelValign {middle} | top | cap | baseline | bottom vertical
% alignment of rho axis tick labels
% RTickValue [vector] vector containing rho axis tick positions
% RTickVisible {on} | off rho axis tick visibility
%
% TGridColor colorspec for theta axis grid color
% TGridLineStyle - | -- | {:} | -. theta axis grid line style
% TGridLineWidth {0.5} theta axis grid line width in points
% TGridVisible {on} | off theta axis grid visibility
% TTickDelta theta axis tick spacing in TTickScale units
% {15 degrees or pi/12 radians}
% TTickDirection {in} | out direction of theta tick marks
% TTickOffset {.08} normalized radial offset of theta tick labels
% TTickLabel string cell array containing theta axis tick labels
% TTickLabelVisible {on} | off visiblity of theta axis tick labels
% TTickSign {+-} | + sign of theta tick labels
% TTickValue [vector] vector of theta ticks in TTickScale units
% TTickVisible {on} | off theta axis tick visibility
% D.C. Hanselman, University of Maine, Orono, ME 04469
% MasteringMatlab@yahoo.com
% Mastering MATLAB 7
% 2005-04-25, 2006-01-18, 2006-04-06, 2006-05-17, 2006-05-18
% 2006-10-03, 2007-03-04, 2008-03-18
%--------------------------------------------------------------------------
% Parse Inputs Parse Inputs
%--------------------------------------------------------------------------
% Find MMPOLAR axes if it exists
nargi=nargin;
% find MMPOLAR axes if it is supplied or if it is the current axes
if nargi>0 && isscalar(varargin{1}) && ishandle(varargin{1})
HAxes=varargin{1}; % see if first argument is an MMPOLAR axes
if strcmp(get(HAxes,'Tag'),'MMPOLAR_Axes')
HFig=ancestor(HAxes,'figure');
HoldIsON=strcmp(get(HAxes,'nextplot'),'add')...
&& strcmp(get(HFig,'nextplot'),'add');
P=getappdata(HAxes,'MMPOLAR_Properties');
Pfn=fieldnames(P);
varargin(1)=[]; % strip initial axes handle off varargin
nargi=nargi-1; % varargin now contains rest of input arguments
else
local_error('First Argument is Not a Valid MMPOLAR Axes Handle.')
end
else % see if MMPOLAR axes is current axes
HFig=get(0,'CurrentFigure');
if isempty(HFig)
HAxes=[];
Pfn=fieldnames(local_getDefaults);
HoldIsON=false;
else
HAxes=get(HFig,'CurrentAxes');
if isempty(HAxes)
Pfn=fieldnames(local_getDefaults);
HoldIsON=false;
else
if strcmp(get(HAxes,'Tag'),'MMPOLAR_Axes')
HoldIsON=strcmp(get(HAxes,'nextplot'),'add')...
&& strcmp(get(HFig,'nextplot'),'add');
P=getappdata(HAxes,'MMPOLAR_Properties');
Pfn=fieldnames(P);
else % no MMPOLAR axes exists
HAxes=[];
Pfn=fieldnames(local_getDefaults);
HoldIsON=false;
set(HAxes,'NextPlot','replace') % hold off
end
end
end
end
%--------------------------------------------------------------------------
% Consider input arguments Consider input arguments
%--------------------------------------------------------------------------
if nargi==0 % MMPOLAR() MMPOLAR() MMPOLAR() MMPOLAR() MMPOLAR() MMPOLAR()
if ~isempty(HAxes)
out=P; % return property structure if it exists
return
else
local_error('No MMPOLAR Axes exists or is not Current Axes.')
end
end
if nargi==1 % Consider SET and GET Requests Consider SET and GET Requests
if ~isempty(HAxes)
arg=varargin{1};
if ischar(arg) % MMPOLAR('Pname') MMPOLAR('Pname') MMPOLAR('Pname')
[fn,errmsg]=local_isfield(Pfn,arg);
error(errmsg)
out=P.(fn);
return
elseif iscellstr(arg) % MMPOLAR({'PName1','PName2',...})
nc=length(arg);
out=cell(1,nc);
for k=1:nc
[fn,errmsg]=local_isfield(Pfn,arg{k});
error(errmsg)
out{k}=P.(fn);
end
return
elseif isstruct(arg) % MMPOLAR(S) MMPOLAR(S) MMPOLAR(S) MMPOLAR(S)
Sfn=fieldnames(arg);
for k=1:length(Sfn)
[fn,errmsg]=local_isfield(Pfn,Sfn{k});
error(errmsg)
S.(fn)=arg.(Sfn{k});
end
local_updatePlot(HAxes,S);
return
else
local_error('Unknown Input Argument.')
end
else
local_error('No MMPOLAR exists or is not Current Axes.')
end
end
% MMPOLAR('PName1',PValue1,'PName2',PValue2,'PName3',PValue3,...)
if rem(nargi,2)==0 && ischar(varargin{1}) && ~isempty(HAxes)
for k=1:2:nargi-1
PName=varargin{k};
if ischar(PName)
[fn,errmsg]=local_isfield(Pfn,PName);
error(errmsg)
S.(fn)=varargin{k+1};
else
local_error('String Input Property Name Argument Expected.')
end
end
local_updatePlot(HAxes,S)
return
elseif ischar(varargin{1}) % Unknown Input Unknown Input Unknown Input
local_error('Unknown Input Arguments or NO MMPOLAR Axes Exists.')
elseif isnumeric(varargin{1})%MMPOLAR(Theta,Rho,...) MMPOLAR(Theta,Rho,...)
% find out if there are appended 'PName',PValue pairs or a structure P
last=[];
k=3; % 'Pname' or P can't appear before 3rd argument
while k<=nargi
vark=varargin{k};
k=k+1;
if ischar(vark)
fn=local_isfield(Pfn,vark);
if ~isempty(fn)
if isempty(last)
last=k-1;
end
S.(fn)=varargin{k};
k=k+1; % skip known PValue
end
elseif isstruct(vark) % found appended structure
if isempty(last)
last=k-1;
end
Sfn=fieldnames(vark);
for ki=1:length(Sfn)
[fn,errmsg]=local_isfield(Pfn,Sfn{ki});
error(errmsg)
S.(fn)=vark.(Sfn{ki});
end
end
end
if ~isempty(last)
varargin(last:end)=[]; % strip properties and values from input
end
else
local_error('Unknown Input Arguments.')
end
%--------------------------------------------------------------------------
% Now have valid data for plotting Now have valid data for plotting
%--------------------------------------------------------------------------
if HoldIsON % a current held plot exists
D=getappdata(HAxes,'MMPOLAR_Data'); % get stored data
P=getappdata(HAxes,'MMPOLAR_Properties');
tmpaxes=axes('Position',get(HAxes,'Position'));
try % the plot function should work with new data
Hlines=plot(tmpaxes,varargin{:});
catch
delete(tmpaxes)
local_error('Input Arguments Not Understood.')
end
D.TData=[D.TData; get(Hlines,{'XData'})]; % add to held data
D.RData=[D.RData; get(Hlines,{'YData'})];
D.LineColor=[D.LineColor; get(Hlines,{'Color'})];
D.LineStyle=[D.LineStyle; get(Hlines,{'LineStyle'})];
D.Marker=[D.Marker; get(Hlines,{'Marker'})];
D.NumLines=length(D.TData);
delete(Hlines) % got the data, lines are no longer needed
delete(D.HLines) % delete original lines as well
set(tmpaxes,'NextPlot','add') % hold on
for k=1:D.NumLines % plot ALL data to find new RTicks and RLimits
plot(tmpaxes,D.TData{k},D.RData{k})
end
P.RLimit=get(tmpaxes,'YLim'); % Rho axis limits
P.RTickValue=get(tmpaxes,'YTick'); % Default Rho axis ticks
delete(tmpaxes) % Temporary axes no longer needed
[P,D]=local_getRTickValue(HAxes,P,D); % get rho tick values
D.RDataN=cell(D.NumLines,1);
for k=1:D.NumLines % normalize rho data for plotting
D.TData(k)={mod(D.TData{k},2*pi)}; % map theta into [0 2*pi]
D.RDataN(k)={(D.RData{k}-D.RMin)/D.RLimitDiff};
end
P.TLimit=[0 2*pi]; % plot full circle
[P,D]=local_getTTickValue(P,D); % get theta tick values
[P,D]=local_placeAxesPatch(HAxes,P,D,1);% draw axes patch, border, ticks
[P,D]=local_placeRGrid(HAxes,P,D,1); % Draw Rho Grid
[P,D]=local_placeTGrid(HAxes,P,D,1); % Draw Theta Grid
[P,D]=local_placeTTickLabel(HAxes,P,D,1); % Add Theta Tick Labels
[P,D]=local_placeRTickLabel(HAxes,P,D,1); % Add Rho Tick Lablels
else % Hold is OFF
try % the plot function should work now
HAxes=newplot; % create axes
D.HLines=plot(HAxes,varargin{:});
catch
delete(gcf)
local_error('Input Arguments Not Understood.')
end
HFig=ancestor(HAxes,'figure');
D.NumLines=length(D.HLines); % get all data for storage
D.TData=get(D.HLines,{'XData'});
D.RData=get(D.HLines,{'YData'});
D.LineColor=get(D.HLines,{'Color'});
D.LineStyle=get(D.HLines,{'LineStyle'});
D.Marker=get(D.HLines,{'Marker'});
P=local_getDefaults; % get default properties, update as needed
P.RLimit=get(HAxes,'YLim'); % Rho axis limits
P.RTickValue=get(HAxes,'YTick'); % Default Rho axis ticks
[P,D]=local_getRTickValue(HAxes,P,D); % get rho tick values
D.RDataN=cell(D.NumLines,1);
for k=1:D.NumLines % Condition plotted data
% wrap angles into first revolution
D.TData{k}=mod(D.TData{k},2*pi);
% normalize rho data for plotting
D.RDataN(k)={(D.RData{k}-D.RMin)/D.RLimitDiff};
end
P.TLimit=[0 2*pi]; % plot full circle
[P,D]=local_getTTickValue(P,D); % get theta tick values
delete(D.HLines) % clear cartesian lines, then create polar axes
[P,D]=local_placeAxesPatch(HAxes,P,D); % draw axes patch, border, ticks
[P,D]=local_placeRGrid(HAxes,P,D); % Draw Rho Grid
[P,D]=local_placeTGrid(HAxes,P,D); % Draw Theta Grid
[P,D]=local_placeTTickLabel(HAxes,P,D); % Add Theta Tick Labels
[P,D]=local_placeRTickLabel(HAxes,P,D); % Add Rho Tick Lablels
end
xylims=[-1 1]*1.08;
% Finalize Axes View Finalize Axes View
set(HAxes,'DataAspectRatio',[1 1 1],....
'XLimMode','manual','YLimMode','manual',...
'XLim',xylims,'YLim',xylims,...
'Visible','Off','Tag','MMPOLAR_Axes')
Hlabels=get(HAxes,{'Xlabel','YLabel', 'Title'});
set([Hlabels{:}],'Visible','on') % make labels visible
% Plot the Data Plot the Data
D.HLines=zeros(D.NumLines,1); % storage for lineseries handles
set([HFig,HAxes],'NextPlot','add') % hold on
for k=1:D.NumLines % plot the normalized data
tdata=D.TData{k};
rdata=D.RDataN{k};
xdata=rdata.*cos(tdata);
ydata=rdata.*sin(tdata);
D.HLines(k)=plot(HAxes,xdata,ydata,...
'Color',D.LineColor{k},...
'LineStyle',D.LineStyle{k},...
'Marker',D.Marker{k});
end
if HoldIsON
set([HFig,HAxes],'NextPlot','add') % hold on
else
set([HFig,HAxes],'NextPlot','replace') % hold off
end
% Store Data Store Data
setappdata(HAxes,'MMPOLAR_Properties',P)
setappdata(HAxes,'MMPOLAR_Data',D)
if nargout % output handles if requested
out=D.HLines;
end
% Update Plot with 'PName' PValue pairs if they exist
if exist('S','var')==1
local_updatePlot(HAxes,S)
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
% Local Functions Local Functions
%--------------------------------------------------------------------------
function local_updatePlot(HAxes,S) % local_updatePlot(HAxes,S)
% update MMPOLAR plot properties
% S contains known properties
P=getappdata(HAxes,'MMPOLAR_Properties');
D=getappdata(HAxes,'MMPOLAR_Data');
Sfn=fieldnames(S);
for kk=1:length(Sfn)
switch Sfn{kk}
case 'Axis' % Axis
[istrue,onoff]=local_isonoff(S.Axis);
if istrue
set(D.HAPatch,'Visible',onoff)
set(D.HRGrid,'Visible',onoff)
set(D.HTGrid,'Visible',onoff)
set(D.HRTick,'Visible',onoff)
set(D.HTTick,'Visible',onoff)
set(D.HRTickLabel,'Visible',onoff)
set(D.HTTickLabel,'Visible',onoff)
P.RGridVisible=onoff;
P.TGridVisible=onoff;
P.RTickLabelVisible=onoff;
P.TTickLabelVisible=onoff;
else
local_error('Unknown ''Axis'' Property Value.')
end
case 'BackgroundColor' % BackgroundColor
[istrue,cs]=local_iscolorspec(S.BackgroundColor);
if istrue
set(D.HAPatch,'FaceColor',cs)
P.BackgroundColor=cs;
else
local_error('Unknown ''BackgroundColor'' Property Value.')
end
case 'Border' % Border
[istrue,onoff]=local_isonoff(S.Border);
if istrue && strcmp(onoff,'on')
set(D.HAPatch,'EdgeColor',P.BorderColor)
set(D.HTTick,'Visible','on')
set(D.HRTick,'Visible','on')
P.RTickVisible='on';
P.TTickVisibel='on';
elseif istrue && strcmp(onoff,'off')
set(D.HAPatch,'EdgeColor','none')
set(D.HTTick,'Visible','off')
set(D.HRTick,'Visible','off')
P.RTickVisible='off';
P.TTickVisibel='off';
else
local_error('Unknown ''Border'' Property Value.')
end
case 'BorderColor' % BorderColor
[istrue,cs]=local_iscolorspec(S.BorderColor);
if istrue
P.BorderColor=cs;
set(D.HAPatch,'EdgeColor',cs)
set(D.HRTick,'Color',cs)
set(D.HTTick,'Color',cs)
else
local_error('Unknown ''BorderColor'' Property Value.')
end
case 'FontName' % FontName
if ischar(S.FontName) && any(strcmpi(listfonts,S.FontName))
set([D.HRTickLabel; D.HTTickLabel],'FontName',S.FontName)
P.FontName=S.FontName;
else
local_error('Unknown ''FontName'' Property Value.')
end
case 'FontSize' % FontSize
if isnumeric(S.FontSize) && isscalar(S.FontSize)
set([D.HRTickLabel; D.HTTickLabel],'FontSize',S.FontSize)
P.FontSize=S.FontSize;
else
local_error('Unknown ''FontSize'' Property Value.')
end
case 'FontWeight' % FontWeight
if ischar(S.FontWeight) && ...
(strncmpi(S.FontWeight,'normal',3)...
||strncmpi(S.FontWeight,'bold',3))
set([D.HRTickLabel; D.HTTickLabel],'FontWeight',S.FontWeight)
P.FontWeight=S.FontWeight;
else
local_error('Unknown ''FontWeight'' Property Value.')
end
case 'Grid' % Grid
[istrue,onoff]=local_isonoff(S.Grid);
if istrue
set(D.HRGrid,'Visible',onoff)
set(D.HTGrid,'Visible',onoff)
P.Grid=onoff;
P.RGridVisible=onoff;
P.TGridVisible=onoff;
else
local_error('Unknown ''Grid'' Property Value.')
end
case 'RGridColor' % RGridColor
[istrue,cs]=local_iscolorspec(S.RGridColor);
if istrue
set(D.HRGrid,'Color',cs)
set(D.HRTickLabel,'Color',cs)
P.RGridColor=cs;
else
local_error('Unknown ''RGridColor'' Property Value.')
end
case 'RGridLineStyle' % RGridLineStyle
if local_islinespec(S.RGridLineStyle)
set(D.HRGrid,'LineStyle',S.RGridLineStyle)
P.RGridLineStyle=S.RGridLineStyle;
else
local_error('Unknown ''RGridLineStyle'' Property Value.')
end
case 'RGridLineWidth' % RGridLineWidth
if isnumeric(S.RGridLineWidth) && isscalar(S.RGridLineWidth)
set(D.HRGrid,'LineWidth',S.RGridLineWidth)
P.RGridLineWidth=S.RGridLineWidth;
else
local_error('Unknown ''RGridLineWidth'' Property Value.')
end
case 'RGridVisible' % RGridVisible
[istrue,onoff]=local_isonoff(S.RGridVisible);
if istrue
set(D.HRGrid,'Visible',onoff)
P.RGridVisible=onoff;
else
local_error('Unknown ''RGridVisible'' Property Value.')
end
case 'RLimit' % RLimit
if isnumeric(S.RLimit) && numel(S.RLimit)==2
S.RLimit=[min(S.RLimit) max(S.RLimit)];
S.RLimit(isinf(S.RLimit))=P.RLimit(isinf(S.RLimit));
[P,D]=local_getRTickValue(HAxes,P,D,S);
[P,D]=local_placeRGrid(HAxes,P,D,S);
[P,D]=local_placeRTickLabel(HAxes,P,D,S);
% rescale rho data to new limits
for k=1:length(D.RData)
D.RDataN(k)={(D.RData{k}-D.RMin)/D.RLimitDiff};
D.RDataN{k}(D.RDataN{k}>1)=NaN; % hide data outside limits
D.RDataN{k}(D.RDataN{k}<0)=NaN;
theta=D.TData{k};
xdata=D.RDataN{k}.*cos(theta);
ydata=D.RDataN{k}.*sin(theta);
set(D.HLines(k),'XData',xdata,'YData',ydata)
end
else
local_error('Unknown ''RLimit'' Property Value.')
end
case 'RTickAngle' % RTickAngle
if isnumeric(S.RTickAngle) && isscalar(S.RTickAngle)
rad=S.RTickAngle;
if strcmp(P.TTickScale,'degrees')
rad=S.RTickAngle*pi/180;
end
if P.TLimit(1)>P.TLimit(2) && (rad<P.TLimit(2) || rad>P.TLimit(1))
P.RTickAngle=S.RTickAngle;
D.RTickAngle=rad;
elseif rad>P.TLimit(1) && rad<P.TLimit(2)
P.RTickAngle=S.RTickAngle;
D.RTickAngle=rad;
else
local_error('RTickAngle not within Theta Axis Limits.')
end
for k=1:D.RTickLabelN % ignore innermost tick
xdata=(P.RTickOffset+D.RTickRadius(k))*cos(D.RTickAngle);
ydata=(P.RTickOffset+D.RTickRadius(k))*sin(D.RTickAngle);
set(D.HRTickLabel(k),'Position',[xdata ydata])
end
phi=asin(P.TickLength./(2*D.RTickRadius));
tdata=[D.RTickAngle-phi; D.RTickAngle+zeros(size(D.RTickRadius))
D.RTickAngle+phi; NaN(size(D.RTickRadius))];
rdata=[D.RTickRadius; D.RTickRadius
D.RTickRadius; NaN(size(D.RTickRadius))];
xdata=rdata(:).*cos(tdata(:));
ydata=rdata(:).*sin(tdata(:));
set(D.HRTick,'XData',xdata,'YData',ydata) % move rho ticks
else
local_error('Unknown ''RTickAngle'' Property Value.')
end
case 'RTickLabel' % RTickLabel
if iscellstr(S.RTickLabel)
NumS=length(S.RTickLabel);
for k=1:D.RTickLabelN
str=S.RTickLabel{rem(k-1,NumS)+1};
set(D.HRTickLabel(k),'String',str)
end
P.RTickLabel=S.RTickLabel;
else
local_error('Unknown ''RTickLabel'' Property Value.')
end
case 'RTickLabelHalign' % RTickLabelHalign
fnames={'left' 'center' 'right'};
out=local_isfield(fnames,S.RTickLabelHalign);
if ~isempty(out)
P.RTickLabelHalign=out;
set(D.HRTickLabel,'HorizontalAlignment',out)
else
local_error('Unknown ''RTickLabelHalign'' Property Value.')
end
case 'RTickLabelValign' % RTickLabelValign
fnames={'top' 'cap' 'middle' 'baseline' 'bottom'};
out=local_isfield(fnames,S.RTickLabelValign);
if ~isempty(out)
P.RTickLabelValign=out;
set(D.HRTickLabel,'VerticalAlignment',out)
else
local_error('Unknown ''RTickLabelValign'' Property Value.')
end
case 'RTickLabelVisible' % RTickLabelVisible
[istrue,onoff]=local_isonoff(S.RTickLabelVisible);
if istrue
set(D.HRTickLabel,'Visible',onoff)
P.RTickLabelVisible=onoff;
else
local_error('Unknown ''RTickLabelVisible'' Property Value.')
end
case 'RTickOffset' % RTickOffset
if isnumeric(S.RTickOffset) && isscalar(S.RTickOffset)
P.RTickOffset=S.RTickOffset;
for k=1:D.RTickLabelN
xdata=(P.RTickOffset+D.RTickRadius(k))*cos(D.RTickAngle);
ydata=(P.RTickOffset+D.RTickRadius(k))*sin(D.RTickAngle);
set(D.HRTickLabel(k),'Position',[xdata ydata])
end
else
local_error('Unknown ''RTickOffset'' Property Value.')
end
case 'RTickUnits' % RTickUnits
if ischar(S.RTickUnits)
tmp=char(get(D.HRTickLabel(end),'String'));
if ~isempty(P.RTickUnits)
idx=strfind(tmp,P.RTickUnits);
tmp=[tmp(1:idx(end)-1) S.RTickUnits];
else
tmp=[tmp S.RTickUnits]; %#ok
end
set(D.HRTickLabel(end),'String',tmp)
P.RTickUnits=S.RTickUnits;
else
local_error('Unknown ''RTickUnits'' Property Value.')
end
case 'RTickValue' % RTickValue
if isnumeric(S.RTickValue) && numel(S.RTickValue)>0
S.RTickValue=S.RTickValue(S.RTickValue>=P.RLimit(1)...
& S.RTickValue<=P.RLimit(2));
if length(S.RTickValue)>1
P.RTickValue=S.RTickValue;
D.RTickLabelN=length(P.RTickValue);
D.RTickRadius=(P.RTickValue-D.RMin)/D.RLimitDiff;
[P,D]=local_placeRGrid(HAxes,P,D,S);
[P,D]=local_placeRTickLabel(HAxes,P,D,S);
end
else
local_error('Unknown ''RTickValue'' Property Value.')
end
case 'RTickVisible' % RTickVisible
[istrue,onoff]=local_isonoff(S.RTickVisible);
if istrue
set(D.HRTick,'Visible',onoff)
P.RTickVisible=onoff;
else
local_error('Unknown ''RTickVisible'' Property Value.')
end
case 'Style' % Style
if strncmpi(S.Style,'cartesian',3) % Cartesian style
set(HAxes,'View',[0 90])
P.TDirection='ccw';
P.TZeroDirection='east';
P.Style='cartesian';
elseif strncmpi(S.Style,'compass',3) % Compass style
set(HAxes,'View',[90 -90])
P.TDirection='cw';
P.TZeroDirection='north';
P.Style='compass';
else
local_error('Unknown ''Style'' Property Value.')
end
case 'TDirection' % TDirection
if ischar(S.TDirection) && strcmpi(S.TDirection,'cw')
P.TDirection='cw';
if strcmp(P.TZeroDirection,'north')
set(HAxes,'View',[90 -90])
elseif strcmp(P.TZeroDirection,'east')
set(HAxes,'View',[0 -90])
elseif strcmp(P.TZeroDirection,'south')
set(HAxes,'View',[270 -90])
elseif strcmp(P.TZeroDirection,'west')
set(HAxes,'View',[180 -90])
end
elseif ischar(S.TDirection) && strcmpi(S.TDirection,'ccw')
P.TDirection='ccw';
if strcmp(P.TZeroDirection,'north')
set(HAxes,'View',[270 90])
elseif strcmp(P.TZeroDirection,'east')
set(HAxes,'View',[0 90])
elseif strcmp(P.TZeroDirection,'south')
set(HAxes,'View',[90 90])
elseif strcmp(P.TZeroDirection,'west')
set(HAxes,'View',[180 90])
end
else
local_error('Unknown ''TDirection'' Property Value.')
end
P.Style='unknown';
case 'TGridColor' % TGridColor
[istrue,cs]=local_iscolorspec(S.TGridColor);
if istrue
set(D.HTGrid,'Color',cs)
set(D.HTTickLabel,'Color',cs)
P.TGridColor=cs;
else
local_error('Unknown ''TGridColor'' Property Value.')
end
case 'TGridLineStyle' % TGridLineStyle
if local_islinespec(S.TGridLineStyle)
set(D.HTGrid,'LineStyle',S.TGridLineStyle)
P.TGridLineStyle=S.TGridLineStyle;
else
local_error('Unknown ''TGridLineStyle'' Property Value.')
end
case 'TGridLineWidth' % TGridLineWidth
if isnumeric(S.TGridLineWidth) && isscalar(S.TGridLineWidth)
set(D.HTGrid,'LineWidth',S.TGridLineWidth)
P.TGridLineWidth=S.TGridLineWidth;
else
local_error('Unknown ''TGridLineWidth'' Property Value.')
end
case 'TGridVisible' % TGridVisible
[istrue,onoff]=local_isonoff(S.TGridVisible);
if istrue
set(D.HTGrid,'Visible',onoff)
P.TGridVisible=onoff;
else
local_error('Unknown ''TGridVisible'' Property Value.')
end
case 'TickLength' % TickLength
if isnumeric(S.TickLength) && isscalar(S.TickLength)
P.TickLength=max(min(abs(S.TickLength),0.1),.001);
tdir=2*strcmp(P.TTickDirection,'in')-1;
tdata=[D.TTickValue;D.TTickValue;NaN(1,D.TTickLabelN)];
rdata=[ones(1,D.TTickLabelN)
(1-tdir*P.TickLength)+zeros(1,D.TTickLabelN)
NaN(1,D.TTickLabelN)];
xdata=rdata(:).*cos(tdata(:));
ydata=rdata(:).*sin(tdata(:));
set(D.HTTick,'XData',xdata,'YData',ydata) % theta ticks
phi=asin(P.TickLength./(2*D.RTickRadius));
tdata=[D.RTickAngle-phi; D.RTickAngle+zeros(size(D.RTickRadius))
D.RTickAngle+phi; NaN(size(D.RTickRadius))];
rdata=[D.RTickRadius; D.RTickRadius
D.RTickRadius; NaN(size(D.RTickRadius))];
xdata=rdata(:).*cos(tdata(:));
ydata=rdata(:).*sin(tdata(:));
set(D.HRTick,'XData',xdata,'YData',ydata) % rho ticks
else
local_error('Unknown ''TickLength'' Property Value.')
end
case 'TLimit' % TLimit
if isnumeric(S.TLimit) && numel(S.TLimit)==2
if abs(diff(S.TLimit))>1.9*pi % make full circle if close
P.TLimit=[0 2*pi];
else
P.TLimit=mod(S.TLimit,2*pi); % move limits to range 0 to 2pi
end
[P,D]=local_getTTickValue(P,D,S);
[P,D]=local_placeAxesPatch(HAxes,P,D,S);
[P,D]=local_placeRGrid(HAxes,P,D,S);
[P,D]=local_placeTGrid(HAxes,P,D,S);
[P,D]=local_placeTTickLabel(HAxes,P,D,S);
[P,D]=local_placeRTickLabel(HAxes,P,D,S);
for k=1:length(D.TData) % hide data outside TLimits
tdata=D.TData{k};
if P.TLimit(1)>P.TLimit(2)
tdata(tdata<P.TLimit(1) & tdata>P.TLimit(2))=NaN;
else
tdata(tdata<P.TLimit(1) | tdata>P.TLimit(2))=NaN;
end
xdata=D.RDataN{k}.*cos(tdata);
ydata=D.RDataN{k}.*sin(tdata);
set(D.HLines(k),'XData',xdata,'YData',ydata)
end
else
local_error('Unknown ''TLimit'' Property Value.')
end
case 'TTickDelta' % TTickDelta
if isnumeric(S.TTickDelta) && isscalar(S.TTickDelta)
if strcmp(P.TTickScale,'degrees')
P.TTickDelta=min(max(abs(S.TTickDelta),5),90);
else
P.TTickDelta=min(max(abs(S.TTickDelta),pi/36),pi/2);
end
[P,D]=local_getTTickValue(P,D,S);
[P,D]=local_placeTGrid(HAxes,P,D,S);
[P,D]=local_placeTTickLabel(HAxes,P,D,S);
else
local_error('Unknown ''TTickDelta'' Property Value.')
end
case 'TTickDirection' % TTickDirection
if ischar(S.TTickDirection) &&...
(strcmpi(S.TTickDirection,'out') || strcmpi(S.TTickDirection,'in'))
P.TTickDirection=S.TTickDirection;
tdir=2*strcmp(P.TTickDirection,'in')-1;
tdata=[D.TTickValue;D.TTickValue;NaN(1,D.TTickLabelN)];
rdata=[ones(1,D.TTickLabelN)
(1-tdir*P.TickLength)+zeros(1,D.TTickLabelN)
NaN(1,D.TTickLabelN)];
xdata=rdata(:).*cos(tdata(:));
ydata=rdata(:).*sin(tdata(:));
set(D.HTTick,'XData',xdata,'YData',ydata) % theta ticks
else
local_error('Unknown ''TTickDirection'' Property Value.')
end
case 'TTickLabel' % TTickLabel
if iscellstr(S.TTickLabel)
NumS=length(S.TTickLabel);
for k=1:D.TTickLabelN
str=S.TTickLabel{rem(k-1,NumS)+1};
set(D.HTTickLabel(k),'String',str)
end
P.TTickLabel=S.TTickLabel;
else
local_error('Unknown ''TTickLabel'' Property Value.')
end
case 'TTickLabelVisible' % TTickLabelVisible
[istrue,onoff]=local_isonoff(S.TTickLabelVisible);
if istrue
set(D.HTTickLabel,'Visible',onoff)
P.TTickLabelVisible=onoff;
else
local_error('Unknown ''TTickLabelVisible'' Property Value.')
end
case 'TTickOffset' % TTickOffset
if isnumeric(S.TTickOffset) && isscalar(S.TTickOffset)
P.TTickOffset=S.TTickOffset;
for k=1:D.TTickLabelN
xdata=(1+P.TTickOffset)*cos(D.TTickValue(k));
ydata=(1+P.TTickOffset)*sin(D.TTickValue(k));
set(D.HTTickLabel(k),'Position',[xdata ydata])
end
else
local_error('Unknown ''TTickOffset'' Property Value.')
end
case 'TTickScale' % TTickScale
if ischar(S.TTickScale) && strncmpi(S.TTickScale,'degrees',3)...
&& strcmp(P.TTickScale,'radians')
P.TTickScale='degrees';
P.TTickDelta=P.TTickDelta*180/pi;
P.RTickAngle=P.RTickAngle*180/pi;
[P,D]=local_getTTickValue(P,D,S);
[P,D]=local_placeTTickLabel(HAxes,P,D,S);
elseif ischar(S.TTickScale) && strncmpi(S.TTickScale,'radians',3)...
&& strcmp(P.TTickScale,'degrees')
P.TTickScale='radians';
P.TTickDelta=P.TTickDelta*pi/180;
P.RTickAngle=P.RTickAngle*pi/180;
[P,D]=local_getTTickValue(P,D,S);
[P,D]=local_placeTTickLabel(HAxes,P,D,S);
elseif ~ischar(S.TTickScale)
local_error('Unknown ''TTickScale'' Property Value.')
end
case 'TTickSign' % TTickSign
if ischar(S.TTickSign)
if strcmp(S.TTickSign,'+')
P.TTickSign='+';
else
P.TTickSign='+-';
end
[P,D]=local_getTTickValue(P,D,S);
[P,D]=local_placeTTickLabel(HAxes,P,D,S);
else
local_error('Unknown ''TTickSign'' Property Value.')
end
case 'TTickValue' % TTickValue
if isnumeric(S.TTickValue) && numel(S.TTickValue)>0
TTick=S.TTickValue(:)';
if strcmp(P.TTickScale,'degrees')
TTick=TTick*pi/180;
end
if P.TLimit(1)>P.TLimit(2)
idx=TTick<=P.TLimit(2) | TTick>=P.TLimit(1); % keepers
else
idx=TTick>=P.TLimit(1) & TTick<=P.TLimit(2); % keepers
end
S.TTickValue=S.TTickValue(idx);
if length(S.TTickValue)>1
P.TTickValue=S.TTickValue(:)';
D.TTickValue=TTick(idx);
D.TTickLabelN=length(P.TTickValue);
[P,D]=local_placeTGrid(HAxes,P,D,S);
[P,D]=local_placeTTickLabel(HAxes,P,D,S);
end
else
local_error('Unknown ''TTickValue'' Property Value.')
end
case 'TTickVisible' % TTickVisible
[istrue,onoff]=local_isonoff(S.TTickVisible);
if istrue
set(D.HTTick,'Visible',onoff)
P.TTickVisible=onoff;
else
local_error('Unknown ''RTickVisible'' Property Value.')
end
case 'TZeroDirection' % TZeroDirection
if ischar(S.TZeroDirection) && strncmpi(S.TZeroDirection,'north',1)
P.TZeroDirection='north';
if strcmp(P.TDirection,'ccw')
set(HAxes,'View',[270 90])
elseif strcmp(P.TDirection,'cw')
set(HAxes,'View',[90 -90])
end
elseif ischar(S.TZeroDirection) && strncmpi(S.TZeroDirection,'east',1)
P.TZeroDirection='east';
if strcmp(P.TDirection,'ccw')
set(HAxes,'View',[0 90])
elseif strcmp(P.TDirection,'cw')
set(HAxes,'View',[0 -90])
end
elseif ischar(S.TZeroDirection) && strncmpi(S.TZeroDirection,'south',1)
P.TZeroDirection='south';
if strcmp(P.TDirection,'ccw')
set(HAxes,'View',[90 90])
elseif strcmp(P.TDirection,'cw')
set(HAxes,'View',[270 -90])
end
elseif ischar(S.TZeroDirection) && strncmpi(S.TZeroDirection,'west',1)
P.TZeroDirection='west';
if strcmp(P.TDirection,'ccw')
set(HAxes,'View',[180 90])
elseif strcmp(P.TDirection,'cw')
set(HAxes,'View',[180 -90])
end
else
local_error('Unknown ''TZeroDirection'' Property Value.')
end
P.Style='unknown';
end
end
setappdata(HAxes,'MMPOLAR_Properties',P)
setappdata(HAxes,'MMPOLAR_Data',D)
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function [out,errmsg]=local_isfield(fnames,str) % local_isfield
% compare str to fnames, if found, return complete fieldname
% otherwise return error and empty string.
% fnames is cell array, str is a string
% outputs are strings
% look for exact match first
idx=find(strcmpi(fnames,str));
if isempty(idx) % no exact match, so look for more general match
idx=find(strncmpi(str,fnames,max(length(str),2)));
end
if numel(idx)==1 % unique match found
out=fnames{idx};
errmsg='';
else % trouble
out='';
errmsg=sprintf('Unknown or Not Unique Property: %s',str);
end
%--------------------------------------------------------------------------
function [istrue,cs]=local_iscolorspec(arg) % local_iscolorspec
% see if arg is a valid color specification including 'none'
rgb={[1 0 0],[0 1 0],[0 0 1],[0 1 1],[1 0 1],[1 1 0],[0 0 0],[1 1 1],'none'};
cc='rgbcmykwn';
istrue=false;
cs=[];
if ~isempty(arg) && ischar(arg)
idx=find(arg(1)==cc);
if ~isempty(idx)
istrue=true;
cs=rgb{idx};
end
elseif ~isempty(arg) && isnumeric(arg)
istrue=all(size(arg)==[1 3])...
&& all(arg>=0) && all(arg<=1);
cs=arg;
else
istrue=false;
end
%--------------------------------------------------------------------------
function istrue=local_islinespec(arg) % local_islinespec
% see if arg is a valid line style specification
str={'-','-.','--',':'};
if isempty(arg)
istrue=false;
elseif ischar(arg) && length(arg)<3
istrue=any(strncmp(str,arg,length(arg)));
else
istrue=false;
end
%--------------------------------------------------------------------------
function [istrue,s]=local_isonoff(arg) % local_isonoff
% see if arg is either on or off
istrue=false;
s='';
if ~isempty(arg) && ischar(arg) && strcmpi(arg,'on')
istrue=true;
s='on';
elseif ~isempty(arg) && ischar(arg) && strcmpi(arg,'off')
istrue=true;
s='off';
end
%--------------------------------------------------------------------------
function local_error(arg)
% Add message identifier to error message and post error
if ~isempty(arg) && ischar(arg)
error('MMPOLAR:error',arg)
end
%--------------------------------------------------------------------------
function [P,D]=local_placeAxesPatch(HAxes,P,D,S) %#ok local_placeAxesPatch
% Draw Axes Border and Patch
tinc=pi/250;
if P.TLimit(1)>P.TLimit(2)
theta=[P.TLimit(1):tinc:(P.TLimit(2)+2*pi-eps) P.TLimit(2)+2*pi];
else
theta=[P.TLimit(1):tinc:P.TLimit(2)-eps P.TLimit(2)];
end
costheta=cos(theta);
sintheta=sin(theta);
if abs(diff(P.TLimit))<2*(1-eps)*pi; % less than 4 quadrant box
xdata=[0 costheta 0];
ydata=[0 sintheta 0];
else % four quadrant box
xdata=costheta;
ydata=sintheta;
end
% let the axes grow for less than 4 quadrant box