comparison toolboxes/MIRtoolbox1.3.2/MIRToolbox/mirmean.m @ 0:e9a9cd732c1e tip

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