Newer
Older
function out=winplot(varargin)
% WINPLOT Windowed plot
% WINPLOT(X [,W,WS]) plots means or variances of the
% sub-vectors of vector X, which have the length W and
% are shifted by the step WS. X can be a two-column
% vector, where the first column would be the time-scale.
%
% WINPLOT(X,W,WS,FLAG) can determine the kind of the
% result, where FLAG can be either a string or a scalar:
% 'mean' or 1 - Mean (1st moment).
% 'var' or 2 - Variance (2nd moment).
% 'std' or 3 - Standard deviation.
% 'median' or 4 - Median.
% 'sqm' or 5 - Squared Mean.
% 'geo' or 6 - Geometric Mean.
% '3rd' or 7 - 3rd moment.
% 'skw' or 8 - Skewness.
% 'kur' or 9 - Kurtosis.
%
% WINPLOT without any arguments calls a demo (the same as the example
% below).
%
% Example: winplot(randn(2000,1),20,20)
%
% See also PLOT.
% Copyright (c) 2002-2003 by AMRON
% Norbert Marwan, Potsdam University, Germany
% http://www.agnld.uni-potsdam.de
%
% $Date$
% $Revision$
%
% $Log$
% Revision 2.2 2004/11/10 07:04:57 marwan
% initial import
%
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
%
% This program is part of the new generation XXII series.
%
% This program is free software; you can redistribute it and/or
% modify it under the terms of the GNU General Public License
% as published by the Free Software Foundation; either version 2
% of the License, or any later version.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% programme properties
global props
init_properties
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% check and read the input
slidebar_off=0;
error(nargchk(0,4,nargin));
if nargout>2, error('Too many output arguments.'), end
x=[]; lag=50;
%h=findobj('Tag','errordialog');
%if ~isempty(h), delete(h), end
if isempty(varargin)
varargin{1}='init';
x(:,2)=randn(2000,1);
x(:,1)=(1:2000)';
w=20;
ws=20;
flag=1;
end
if ischar(varargin{1})
action=varargin{1};
else
i_double=find(cellfun('isclass',varargin,'double'));
i_char=find(cellfun('isclass',varargin,'char'));
%%%%%% get the numeric input variables
if ~isempty(i_double)
for i=1:length(i_double),
if i==1
x=getx(varargin{i_double(i)});
w=round(.1*length(x));
ws=round(.1*length(x));
flag=1;
elseif i==2
w=varargin{i_double(i)};
if max(size(w))>1, warning('Window size must be scalar. Using the first value.'); w=w(1); end
elseif i==3
ws=varargin{i_double(i)};
if max(size(ws))>1, warning('Window step value must be scalar. Using the first value.'); ws=ws(1); end
elseif i==4
flag=varargin{i_double(i)};
if max(size(flag))>1, warning('Window step value must be scalar. Using the first value.'); flag=flag(1); end
if flag>9, warning(['''',num2str(flag),''' is not a supported method. ''1'' (''mean'') will be used instead.']), flag=1; end
end
end
else
error('No data set found.')
end
%%%%%% get the method
check_meth={'mea','var','std','med','sqm','geo','3rd','skw','kur'}; % gui, nogui, silent
if ~isempty(i_char)
temp_meth=0;
for i=1:length(i_char),
temp_meth=temp_meth+strcmpi(varargin{i_char(i)}(1:3),check_meth');
end
flag=min(find(temp_meth));
if isempty(flag) | flag>length(check_meth)
warning(['''',varargin{i_char(1)},''' is not a supported method. ''mean'' will be used instead.'])
flag=1;
end
end
if w>length(x), error('Window size cannot be larger than the length of data.'), end
action='init';
if nargout
flag=-flag;
end
if flag<0
try
out=plot_result(x,w,ws,flag);
action='none';
catch
error(lasterr)
end
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% splash the GPL
splash_gpl('winplot');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% switch routines
try
switch(action)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% initialization
case 'init'
if ~isempty(findobj('Tag','winplot_fig'))
% delete(findobj('Tag','winplot_fig'))
end
h=figure(props.window,... % Plot Figure
'Tag','winplot_fig',...
'MenuBar','Figure',...
'Position',[69.5000 39.6429 120.0000 30.0714],...
'Name','Windowed Plot',...
'DeleteFcn','winplot close',...
'WindowButtonMotionFcn','winplot motion',...
'PaperPosition',[0.25 0.25 7.7677 11.193],...
'PaperType','a4',...
'PaperOrientation','portrait',...
'UserData',x);
set(0,'showhidden','on')
h=findobj('Label','&Help','Type','uimenu');
if isempty(h)
h=uimenu('Label','&Help');
h2=uimenu('Parent',h(1),'Label','&Help Winplot','Callback','helpwin winplot');
else
h1=flipud(get(h(1),'Children'));
set(h1(1),'Separator','on')
h2=uimenu('Parent',h(1),'Label','&Help Winplot','Callback','helpwin winplot');
copyobj(h1,h(1))
delete(h1)
end
set(0,'showhidden','off')
h=axes(props.axes,...
'Position',[89 24.8 6.8 3.5]);
logo=load('logo');
h2=imagesc([logo.logo fliplr(logo.logo)]);
set(h2,'Tag','uniLogo')
set(h,props.logo,'Tag','axes_logo')
h=uicontrol(props.text,...
'Tag','text',...
'String','Uni Potsdam',...
'Position',[97 24.2143 22 3.5714]);
h2=textwrap(h,{' AGNLD','University of Potsdam','2002'});
set(h,'String',h2)
h=axes(props.axes,...
'Tag','winplot_axes',...
'Box','On',...
'Position',[9 3.5 72.8333 23.0714]);
h=uicontrol(props.frame,...
'Tag','frame',...
'Position',[91.5000 1.3571 23.5000 20.7857]);
h=uicontrol(props.text,...
'Tag','text',...
'String','Window size',...
'Position',[94.8333 20 16.8333 1.5000]);
h=uicontrol(props.edit,...
'Tag','edit_w',...
'String',num2str(w),...
'CallBack','winplot update',...
'Position',[94.8333 18.5714 16.8333 1.5000]);
h=uicontrol(props.slider,...
'Tag','slider_w',...
'Max',length(x),...
'Min',1,...
'Sliderstep',[1/length(x) 10/length(x)],...
'Value',w,...
'CallBack','winplot wsize',...
'Position',[94.8333 17.4 16.8333 1.2]);
if slidebar_off, set(h,'Visible','off'), end
h=uicontrol(props.text,...
'Tag','text',...
'String','Window Step',...
'Position',[94.8333 15.2 16.8333 1.5000]);
h=uicontrol(props.edit,...
'Tag','edit_ws',...
'String',num2str(ws),...
'CallBack','winplot update',...
'Position',[94.8333 13.7714 16.8333 1.5000]);
h=uicontrol(props.slider,...
'Tag','slider_ws',...
'Max',length(x)-1,...
'Min',1,...
'Value',ws,...
'Sliderstep',[1/(length(x)-1) 10/(length(x)-1)],...
'CallBack','winplot wstep',...
'Position',[94.8333 12.4 17.0333 1.2]);
if slidebar_off, set(h,'Visible','off'), end
h=uicontrol(props.text,...
'Tag','text_conf',...
'String','Conf.level:',...
'Position',[94.8333 10.0 16.8333 1.5000]);
h=uicontrol(props.edit,...
'Tag','edit_conf',...
'String',num2str(0.05),...
'CallBack','winplot update',...
'Position',[105.6666 10.2 6 1.5000]);
h=uicontrol(props.popup,...
'Tag','button_flag',...
'String','Mean|Variance|StdDev|Median|SquaredMean|GeoMean|3rdMoment|Skewness|Kurtosis',...
'CallBack','winplot update',...
'Value',flag,...
'Position',[95 7.7857 16.8333 1.8000]);
h=uicontrol(props.button,...
'Tag','button_print',...
'CallBack','winplot print',...
'String','Print',...
'Position',[94.8333 4.9286 16.8333 2.2143]);
h=uicontrol(props.button,...
'Tag','button_close',...
'CallBack','winplot close',...
'String','Close',...
'Position',[94.8333 2.1429 16.8333 2.2143]);
tags={'winplot_fig';'text_conf';'edit_conf';'axes_logo';'text';'winplot_axes';'frame';'edit_w';'slider_w';'edit_ws';'slider_ws';'button_flag';'button_print';'button_close';};
h=[];
for i=1:length(tags); h=[h; findobj('Tag',tags{i})]; end
set(h,'Units','Norm');
plot_result(x,w,ws,flag);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% wsize
case 'wsize'
h=findobj('Tag','slider_w','Parent',gcf);
w=round(get(h,'Value'));
h=findobj('Tag','edit_w','Parent',gcf);
set(h,'String',num2str(w))
winplot update
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% wsstep
case 'wstep'
h=findobj('Tag','slider_ws','Parent',gcf);
ws=round(get(h,'Value'));
h=findobj('Tag','edit_ws','Parent',gcf);
set(h,'String',num2str(ws))
winplot update
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% update plot
case 'update'
h=findobj('Tag','winplot_fig'); h=h(1);
x=get(h,'UserData');
h=findobj('Tag','edit_w','Parent',gcf);
w=round(str2num(get(h,'String')));
set(h,'String',num2str(w))
h=findobj('Tag','slider_w','Parent',gcf);
set(h,'Value',w)
h=findobj('Tag','edit_ws','Parent',gcf);
ws=round(str2num(get(h,'String')));
set(h,'String',num2str(ws))
h=findobj('Tag','slider_ws','Parent',gcf);
set(h,'Value',ws)
h=findobj('Tag','button_flag','Parent',gcf);
flag=get(h,'Value');
h=findobj('Tag','edit_conf','Parent',gcf);
h2=findobj('Tag','text_conf','Parent',gcf);
if flag~=1 & flag~=2 & flag~=3
set(h,'Enable','Off')
set(h2,'Enable','Off')
else
set(h,'Enable','On')
set(h2,'Enable','On')
end
plot_result(x,w,ws,flag);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% print
case 'print'
h=findobj('Tag','uniLogo');
h_axes=findobj('Tag','winplot_axes','Parent',gcf); h_axes=h_axes(1);
h=[h; findobj('Tag','text','Parent',gcf)];
h=[h; findobj('Tag','frame','Parent',gcf)];
h=[h; findobj('Tag','edit_w','Parent',gcf)];
h=[h; findobj('Tag','slider_w','Parent',gcf)];
h=[h; findobj('Tag','edit_ws','Parent',gcf)];
h=[h; findobj('Tag','slider_ws','Parent',gcf)];
h=[h; findobj('Tag','button_flag','Parent',gcf)];
h=[h; findobj('Tag','button_print','Parent',gcf)];
h=[h; findobj('Tag','button_close','Parent',gcf)];
h=[h; findobj('Tag','edit_conf','Parent',gcf)];
h=[h; findobj('Tag','text_conf','Parent',gcf)];
set(gcf,'WindowButtonMotionFcn','')
set(h,'Visible','Off')
set(h_axes,'Units','Character')
old_pos=get(h_axes,'Position');
set(h_axes,'Units','normalize','Position',[0.1300 0.1100 0.7750 0.8150])
h_dlg=printdlg;
waitfor(h_dlg)
set(h_axes,'Units','Character','Position',old_pos)
set(h_axes,'Units','normalize')
set(h,'Visible','On')
set(gcf,'WindowButtonMotionFcn','winplot motion')
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% motion
case 'motion'
% read data, dim and lag
h_fig=findobj('Tag','winplot_fig'); h_fig=h_fig(1);
x=get(h_fig,'UserData');
h=findobj('Tag','edit_w','Parent',h_fig);
w=round(str2num(get(h,'String')));
set(h,'String',num2str(w))
h=findobj('Tag','slider_w','Parent',h_fig);
set(h,'Value',w)
h=findobj('Tag','edit_ws','Parent',h_fig);
ws=round(str2num(get(h,'String')));
set(h,'String',num2str(ws))
h=findobj('Tag','slider_ws','Parent',h_fig);
set(h,'Value',ws)
h=findobj('Tag','button_flag','Parent',h_fig);
flag=get(h,'Value');
h_axes=findobj('Tag','winplot_axes','Parent',h_fig);
h=findobj('Tag','result_line','Parent',h_axes);
if ~isempty(h)
y(:,1)=get(h(1),'XData')';
y(:,2)=get(h(1),'YData')';
else
plot_result(x,w,ws,flag);
h=findobj('Tag','result_line','Parent',h_axes);
y(:,1)=get(h(1),'XData')';
y(:,2)=get(h(1),'YData')';
end
pointer_prefs=getptr(h_fig);
pointer_prefs=cell2struct(pointer_prefs(2:2:end),pointer_prefs(1:2:end),2);
bad_pointer=setptr(props.glasspointer);
bad_pointer=cell2struct(bad_pointer(2:2:end),bad_pointer(1:2:end),2);
fnames=fieldnames(pointer_prefs);
i=find(strcmpi(fnames,'Pointer'));
if strcmpi(getfield(pointer_prefs,fnames{i}),'custom')
i=find(strcmpi(fnames,'PointerShapeCData'));
shape_pointer=getfield(pointer_prefs,fnames{i});
shape_pointer(isnan(shape_pointer))=0;
fnames_bad_pointer=fieldnames(bad_pointer);
i=find(strcmpi(fnames_bad_pointer,'PointerShapeCData'));
shape_bad_pointer=getfield(bad_pointer,fnames_bad_pointer{i});
shape_bad_pointer(isnan(shape_bad_pointer))=0;
if ~prod(prod(double(shape_pointer==shape_bad_pointer)))
set(h_axes,'UserData',pointer_prefs)
else
pointer_prefs=get(h_axes,'UserData');
end
else
set(h_axes,'UserData',pointer_prefs)
end
xlim=get(h_axes,'xlim');
ylim=get(h_axes,'ylim');
axis_delta=[diff(xlim) diff(ylim)];
% cursor hover axes?
pos=get(h_axes,'CurrentPoint');
if pos(1,1)>=xlim(1) & pos(1,1)<=xlim(2) & pos(1,2)>=ylim(1) & pos(1,2)<=ylim(2)
% cursor hover line? (within 1% of point centers)
tolerance=.01;
is_x1=abs(y(:,1)-pos(1,1)) < tolerance*axis_delta(1);
is_x2=abs(y(:,1)-pos(2,1)) < tolerance*axis_delta(1);
is_y1=abs(y(:,2)-pos(1,2)) < tolerance*axis_delta(2);
is_y2=abs(y(:,2)-pos(2,2)) < tolerance*axis_delta(2);
res1=is_x1.*is_y1;
res2=is_x2.*is_y2;
% show index and change cursor
index1=find(res1);index2=find(res2);
h_index_axes=findobj('Tag','index_axes','Parent',h_fig);
h=findobj('Tag','index_text','Parent',h_index_axes);
if isempty(h_index_axes)
h_index_axes=axes(props.axesindex,'Tag','index_axes');
end
if isempty(h)
h=text(props.textindex,'Units','norm','Tag','index_text','Parent',h_index_axes);
end
h=h(1); h_index_axes=h_index_axes(1);
h_point=findobj('Tag','markedPoint','Parent',h_axes);
set(h_point,'Visible','Off')
if ~isempty(index1)
setptr(h_fig,props.glasspointer)
tx_pos=[y(index1(1),1)+.04*axis_delta(1) y(index1(1),2)+.01*axis_delta(2) 0];
tx=num2str(y(index1(1),2));
set(h,'String',[' ',tx],'Visible','On','Units','Pixel')
set(h_index_axes,'Visible','On')
tx_ext=get(h,'Extent');
set(h_axes,'Units','Pixel')
ax_pos=get(h_axes,'Position');
set(h_axes,'Units','Norm')
xlim=get(h_axes,'Xlim');
ylim=get(h_axes,'Ylim');
x_offset=(tx_pos(1)-xlim(1))*ax_pos(3)/abs(diff(xlim))+ax_pos(1);
y_offset=(tx_pos(2)-ylim(1))*ax_pos(4)/abs(diff(ylim))+ax_pos(2);
set(h_index_axes,'Position',[x_offset y_offset tx_ext(3) tx_ext(4)])
set(h_point,'Position',[y(index1(1),1) y(index1(1),2) 0],'Visible','On')
elseif ~isempty(index2)
setptr(h_fig,props.glasspointer)
tx_pos=[y(index2(1),1)+.04*axis_delta(1) y(index2(1),2)+.01*axis_delta(2) 0];
tx=num2str(y(index2(1),2));
% set(h,'Position',tx_pos,'String',[' ',tx],'Visible','On')
set(h_point,'Position',[y(index2(1),1) y(index2(1),2) 0],'Visible','On')
else
set(h_fig,pointer_prefs)
set(h,'Visible','Off')
set(h_index_axes,'Visible','Off')
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% close
case 'close'
delete(gcf)
end
try, set(0,props.root), end
set(0,'ShowHidden','off')
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% error handling
%if 0
catch
if ~isempty(findobj('Tag','TMWWaitbar')), delete(findobj('Tag','TMWWaitbar')), end
cmd={['mean'];['var'];['std'];['median'];['squmean'];['geomean'];['bias'];['skewness'];['kurtosis']};
z=whos;x=lasterr;y=lastwarn;in=varargin{1};
if ischar(in), in2=in; else, in2=[]; end
in=whos('in');
if ~strcmpi(lasterr,'Interrupt')
fid=fopen('error.log','w');
err=fprintf(fid,'%s\n','Please send us the following error report. Provide a brief');
err=fprintf(fid,'%s\n','description of what you were doing when this problem occurred.');
err=fprintf(fid,'%s\n','E-mail or FAX this information to us at:');
err=fprintf(fid,'%s\n',' E-mail: marwan@agnld.uni-potsdam.de');
err=fprintf(fid,'%s\n',' Fax: ++49 +331 977 1142');
err=fprintf(fid,'%s\n\n\n','Thank you for your assistance.');
err=fprintf(fid,'%s\n',repmat('-',50,1));
err=fprintf(fid,'%s\n',datestr(now,0));
err=fprintf(fid,'%s\n',['Matlab ',char(version),' on ',computer]);
err=fprintf(fid,'%s\n',repmat('-',50,1));
err=fprintf(fid,'%s\n',x);
err=fprintf(fid,'%s\n',y);
err=fprintf(fid,'%s\n',[' during ==> winplot:',action]);
err=fprintf(fid,'%s\n',[' method ==> ',cmd{flag}]);
err=fprintf(fid,'%s',[' input ==> ',in.class]);
if ~isempty(in2), err=fprintf(fid,'\t%s\n',[' (',in2,')']); end
err=fprintf(fid,'%s\n',[' errorcode ==> no errorcode available']);
err=fprintf(fid,'%s\n',' workspace dump ==>');
if ~isempty(z),
err=fprintf(fid,'%s\n',['Name',char(9),'Size',char(9),'Bytes',char(9),'Class']);
for j=1:length(z);
err=fprintf(fid,'%s\n',[z(j).name,char(9),num2str(z(j).size),char(9),num2str(z(j).bytes),char(9),z(j).class]);
end, end
err=fclose(fid);
disp('------------------------------');
disp(' ERROR OCCURED');
disp(' during executing winplot');
disp('------------------------------');
disp(x);
disp([' during ',action]);
disp('----------------------------');
disp(' Please send us the error report. For your convenience, ')
disp(' this information has been recorded in: ')
disp([' ',fullfile(pwd,'error.log')]), disp(' ')
disp(' Provide a brief description of what you were doing when ')
disp(' this problem occurred.'), disp(' ')
disp(' E-mail or FAX this information to us at:')
disp(' E-mail: marwan@agnld.uni-potsdam.de')
disp(' Fax: ++49 +331 977 1142'), disp(' ')
disp(' Thank you for your assistance.')
warning('on')
end
set(0,props.root)
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% plot result
function y=plot_result(x,w,ws,flag)
global props
plotflag=1;
if flag<0; flag=-flag; plotflag=0; end
warning off
if plotflag, setptr(gcf,'watch'), end
cmd={['mean'];['var'];['std'];['median'];['squmean'];['geomean'];['bias'];['skewness'];['kurtosis']};
ylabel_text={'Mean';'Variance';'Std. Deviation';'Median';'Squared Mean';'Geo. Mean';'3rd Moment';'Skewness';'Kurtosis'};
steps=ceil((length(x)+ws-w)/ws);
N=steps*ws+w-ws; x0=x;
if N>length(x), x(end+1:N,:)=NaN; end
if strcmpi(cmd{flag},'geomean')
if any(any(x<0))
if plotflag
h=errordlg('The data have not to be negative for the geometric mean.','Winplot');
set(h,'Tag','errordialog',props.msgboxwin),h2=guihandles(h);set(h2.OKButton,props.msgbox)
uiwait(h)
h=findobj('Tag','button_flag','Parent',gcf);
set(h,'Value',1)
setptr(gcf,'arrow')
else
error('The data have not to be negative for the geometric mean.')
end
return
end
end
for i=0:steps-1;
x1=x((i*ws)+1:(i*ws)+w,2);
x1(isnan(x1))=[];
if isempty(x1), x1=[0;0]; end
y(i+1)=eval([cmd{flag},'(x1)']);
vs(i+1)=var(x1);
vm(i+1)=mean(x1);
xscale(i+1)=x(i*ws+1,1);
end
xscale=[xscale, x0(end,1)];
y=[y, y(end)];
if plotflag
h_fig=findobj('Tag','winplot_fig'); h_fig=h_fig(1);
figure(h_fig(1))
h_axes=findobj('Tag','winplot_axes','Parent',h_fig);
set(h_fig,'CurrentAxes',h_axes)
h=get(h_axes,'Title');
old_title=get(h,'String');
h=get(h_axes,'XLabel');
old_xlabel=get(h,'String');
% confidence intervals
h=findobj('Tag','conf_interval','Parent',h_axes);
if ~isempty(h)
delete(h)
end
h=findobj('Tag','edit_conf','Parent',gcf);
alpha=str2num(get(h,'String'));
n=w-1;
conf_flag=0;
switch(flag)
case 2
% variance
conf_up=n*vs/chi2inv(1-alpha/2,n);
conf_dn=n*vs/chi2inv(alpha/2,n);
conf_flag=1;
case 3
% standard deviation
conf_up=sqrt(vs/finv(alpha/2,length(x),n));
conf_dn=sqrt(vs*finv(alpha/2,n,length(x)));
conf_flag=1;
case 1
% mean
conf_up=vm+tinv(1-alpha/2,n)*vs/sqrt(n);
conf_dn=vm-tinv(1-alpha/2,n)*vs/sqrt(n);
conf_flag=1;
end
if conf_flag
d_conf_x=diff(xscale); d_conf_x=0;
conf_x=xscale(1:end-1);
conf_x=repmat(conf_x,2,1);
conf_x=conf_x(:);
conf_x=[conf_x' 2*conf_x(end)-conf_x(end-1) 2*conf_x(end)-conf_x(end-1) fliplr(conf_x')];
conf_x(1)=[];
conf_dn=repmat(conf_dn,2,1);
conf_dn=conf_dn(:);
conf_up=repmat(conf_up,2,1);
conf_up=conf_up(:);
conf_y=[conf_dn' fliplr(conf_up') conf_dn(1)];
h=patch(conf_x,conf_y,[1 1 1]);
set(h,props.patch,'Tag','conf_interval')
hold on
end
% plot stairs line
h=findobj('Tag','result_line','Parent',h_axes);
if ~isempty(h)
delete(h)
end
h=stairs(xscale,y);
set(h,'Tag','result_line',props.line);
xlabel(old_xlabel)
title(old_title)
set(h_axes,'Tag','winplot_axes','YLimMode','auto')
text(0,0,0,'o','Tag','markedPoint',props.glass)
grid on
setptr(gcf,'arrow')
ylabel(ylabel_text{flag})
end
y(2,:)=xscale;
y=rot90(y,-1);
warning on
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% y=getx(x)
function y=getx(x)
if size(x,1)==1
y(:,1)=(1:length(x))';
y(:,2)=x(1,:)';
else
if size(x,2)>1
if sum(diff(x(:,1))<0)
y(:,1)=(1:length(x))';
y(:,2)=x(:,1);
else
y(:,1)=x(:,1);
y(:,2)=x(:,2);
% error('X-scale must be monotonically non-decreasing.')
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
else
y(:,1)=(1:length(x))';
y(:,2)=x;
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% special function :: squared mean
function y=squmean(x)
y=mean(x).^2;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% special function :: 3rd moment
function y=bias(x)
y=mean((x-mean(x)).^3)^(1/3);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% special function :: skewness
function y=skewness(x)
xs=sort(x); N=length(x);
dz1=xs(ceil(N/10));
dz9=xs(floor(N-N/10));
%q1=xs(ceil(N/4));
%q3=xs(floor(N-N/4));
x2 = 0.33*(dz1 + median(x) + dz9);
y=3*(x2-median(x))/std(x); % Schiefe I
%y=(dz9+dz1-2*median(x))/(dz9-dz1); % Schiefe II
%y=(q3+q1-2*median(x))/(q3-q1); % Schiefe III
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% special function :: kurtosis
function y=kurtosis(x)
% xs=sort(x); N=length(x);
% dz1=xs(ceil(N/10));
% dz9=xs(floor(N-N/10));
% q1=xs(ceil(N/4));
% q3=xs(floor(N-N/4));
% y=(q3-q1)/(2*(dz9-dz1)); % def. Sachs, Angewandte Statistik, 1997
x=(x-mean(x))/std(x);
y=mean(x.^4)-3*mean(x.^2)^2; % def. Hyvaerinen et al., ICA, 2001