wolffd@0
|
1 function varargout = mirmean(f,varargin)
|
wolffd@0
|
2 % m = mirmean(f) returns the mean along frames of the feature f
|
wolffd@0
|
3 %
|
wolffd@0
|
4 % f can be a structure array composed of features. In this case,
|
wolffd@0
|
5 % m will be structured the same way.
|
wolffd@0
|
6
|
wolffd@0
|
7 if isa(f,'mirstruct')
|
wolffd@0
|
8 data = get(f,'Data');
|
wolffd@0
|
9 for fi = 1:length(data)
|
wolffd@0
|
10 data{fi} = mirmean(data{fi});
|
wolffd@0
|
11 end
|
wolffd@0
|
12 varargout = {set(f,'Data',data)};
|
wolffd@0
|
13 elseif isstruct(f)
|
wolffd@0
|
14 fields = fieldnames(f);
|
wolffd@0
|
15 for i = 1:length(fields)
|
wolffd@0
|
16 field = fields{i};
|
wolffd@0
|
17 stat.(field) = mirmean(f.(field));
|
wolffd@0
|
18 end
|
wolffd@0
|
19 varargout = {stat};
|
wolffd@0
|
20 else
|
wolffd@0
|
21 specif.nochunk = 1;
|
wolffd@0
|
22 varargout = mirfunction(@mirmean,f,varargin,nargout,specif,@init,@main);
|
wolffd@0
|
23 end
|
wolffd@0
|
24
|
wolffd@0
|
25
|
wolffd@0
|
26 function [x type] = init(x,option)
|
wolffd@0
|
27 type = '';
|
wolffd@0
|
28
|
wolffd@0
|
29
|
wolffd@0
|
30 function m = main(f,option,postoption)
|
wolffd@0
|
31 if iscell(f)
|
wolffd@0
|
32 f = f{1};
|
wolffd@0
|
33 end
|
wolffd@0
|
34 if isa(f,'mirhisto')
|
wolffd@0
|
35 warning('WARNING IN MIRMEAN: histograms are not taken into consideration yet.')
|
wolffd@0
|
36 m = struct;
|
wolffd@0
|
37 return
|
wolffd@0
|
38 end
|
wolffd@0
|
39 fp = get(f,'FramePos');
|
wolffd@0
|
40 ti = get(f,'Title');
|
wolffd@0
|
41 if 0 %get(f,'Peaks')
|
wolffd@0
|
42 if not(isempty(get(f,'PeakPrecisePos')))
|
wolffd@0
|
43 stat = addstat(struct,get(f,'PeakPrecisePos'),fp,'PeakPos');
|
wolffd@0
|
44 stat = addstat(stat,get(f,'PeakPreciseVal'),fp,'PeakMag');
|
wolffd@0
|
45 else
|
wolffd@0
|
46 stat = addstat(struct,get(f,'PeakPosUnit'),fp,'PeakPos');
|
wolffd@0
|
47 stat = addstat(stat,get(f,'PeakVal'),fp,'PeakMag');
|
wolffd@0
|
48 end
|
wolffd@0
|
49 else
|
wolffd@0
|
50 d = get(f,'Data');
|
wolffd@0
|
51 end
|
wolffd@0
|
52 l = length(d);
|
wolffd@0
|
53 for i = 1:l
|
wolffd@0
|
54 if iscell(d{i})
|
wolffd@0
|
55 if length(d{i}) > 1
|
wolffd@0
|
56 error('ERROR IN MIRMEAN: segmented data not accepted yet.');
|
wolffd@0
|
57 else
|
wolffd@0
|
58 dd = d{i}{1};
|
wolffd@0
|
59 end
|
wolffd@0
|
60 else
|
wolffd@0
|
61 dd = d{i};
|
wolffd@0
|
62 end
|
wolffd@0
|
63 %dd = uncell(dd);
|
wolffd@0
|
64 if 0 %iscell(dd)
|
wolffd@0
|
65 j = 0;
|
wolffd@0
|
66 singul = 1;
|
wolffd@0
|
67 ddd = [];
|
wolffd@0
|
68 while j<length(dd) && singul
|
wolffd@0
|
69 j = j+1;
|
wolffd@0
|
70 if length(dd{j}) > 1
|
wolffd@0
|
71 singul = 0;
|
wolffd@0
|
72 elseif length(dd{j}) == 1
|
wolffd@0
|
73 ddd(end+1) = dd{j};
|
wolffd@0
|
74 end
|
wolffd@0
|
75 end
|
wolffd@0
|
76 if singul
|
wolffd@0
|
77 dd = ddd;
|
wolffd@0
|
78 end
|
wolffd@0
|
79 end
|
wolffd@0
|
80 if iscell(dd)
|
wolffd@0
|
81 m{i} = {zeros(1,length(dd))};
|
wolffd@0
|
82 for j = 1:length(dd)
|
wolffd@0
|
83 m{i}{1}(j) = mean(dd{j});
|
wolffd@0
|
84 end
|
wolffd@0
|
85 elseif size(dd,2) < 2
|
wolffd@0
|
86 nonan = find(not(isnan(dd)));
|
wolffd@0
|
87 dn = dd(nonan);
|
wolffd@0
|
88 m{i}{1} = mean(dn,2);
|
wolffd@0
|
89 else
|
wolffd@0
|
90 %diffp = fp{i}{1}(1,2:end) - fp{i}{1}(1,1:end-1);
|
wolffd@0
|
91 %if round((diffp(2:end)-diffp(1:end-1))*1000)
|
wolffd@0
|
92 % Not regular sampling (in mirattacktime for instance)
|
wolffd@0
|
93 % framesampling = NaN;
|
wolffd@0
|
94 %else
|
wolffd@0
|
95 % framesampling = fp{i}{1}(1,2)-fp{i}{1}(1,1);
|
wolffd@0
|
96 %end
|
wolffd@0
|
97 dd = mean(dd,4);
|
wolffd@0
|
98 m{i} = {NaN(size(dd,1),1,size(dd,3))};
|
wolffd@0
|
99 for k = 1:size(dd,1)
|
wolffd@0
|
100 for l = 1:size(dd,3)
|
wolffd@0
|
101 dk = dd(k,:,l);
|
wolffd@0
|
102 nonan = find(not(isnan(dk)));
|
wolffd@0
|
103 if not(isempty(nonan))
|
wolffd@0
|
104 dn = dk(nonan);
|
wolffd@0
|
105 m{i}{1}(k,1,l) = mean(dn,2);
|
wolffd@0
|
106 end
|
wolffd@0
|
107 end
|
wolffd@0
|
108 end
|
wolffd@0
|
109 end
|
wolffd@0
|
110 end
|
wolffd@0
|
111 m = mirscalar(f,'Data',m,'Title',['Average of ',ti]); |