annotate toolboxes/MIRtoolbox1.3.2/MIRToolbox/mirmean.m @ 0:cc4b1211e677 tip

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