wolffd@0: function varargout = mirmean(f,varargin) wolffd@0: % m = mirmean(f) returns the mean along frames of the feature f wolffd@0: % wolffd@0: % f can be a structure array composed of features. In this case, wolffd@0: % m will be structured the same way. wolffd@0: wolffd@0: if isa(f,'mirstruct') wolffd@0: data = get(f,'Data'); wolffd@0: for fi = 1:length(data) wolffd@0: data{fi} = mirmean(data{fi}); wolffd@0: end wolffd@0: varargout = {set(f,'Data',data)}; wolffd@0: elseif isstruct(f) wolffd@0: fields = fieldnames(f); wolffd@0: for i = 1:length(fields) wolffd@0: field = fields{i}; wolffd@0: stat.(field) = mirmean(f.(field)); wolffd@0: end wolffd@0: varargout = {stat}; wolffd@0: else wolffd@0: specif.nochunk = 1; wolffd@0: varargout = mirfunction(@mirmean,f,varargin,nargout,specif,@init,@main); wolffd@0: end wolffd@0: wolffd@0: wolffd@0: function [x type] = init(x,option) wolffd@0: type = ''; wolffd@0: wolffd@0: wolffd@0: function m = main(f,option,postoption) wolffd@0: if iscell(f) wolffd@0: f = f{1}; wolffd@0: end wolffd@0: if isa(f,'mirhisto') wolffd@0: warning('WARNING IN MIRMEAN: histograms are not taken into consideration yet.') wolffd@0: m = struct; wolffd@0: return wolffd@0: end wolffd@0: fp = get(f,'FramePos'); wolffd@0: ti = get(f,'Title'); wolffd@0: if 0 %get(f,'Peaks') wolffd@0: if not(isempty(get(f,'PeakPrecisePos'))) wolffd@0: stat = addstat(struct,get(f,'PeakPrecisePos'),fp,'PeakPos'); wolffd@0: stat = addstat(stat,get(f,'PeakPreciseVal'),fp,'PeakMag'); wolffd@0: else wolffd@0: stat = addstat(struct,get(f,'PeakPosUnit'),fp,'PeakPos'); wolffd@0: stat = addstat(stat,get(f,'PeakVal'),fp,'PeakMag'); wolffd@0: end wolffd@0: else wolffd@0: d = get(f,'Data'); wolffd@0: end wolffd@0: l = length(d); wolffd@0: for i = 1:l wolffd@0: if iscell(d{i}) wolffd@0: if length(d{i}) > 1 wolffd@0: error('ERROR IN MIRMEAN: segmented data not accepted yet.'); wolffd@0: else wolffd@0: dd = d{i}{1}; wolffd@0: end wolffd@0: else wolffd@0: dd = d{i}; wolffd@0: end wolffd@0: %dd = uncell(dd); wolffd@0: if 0 %iscell(dd) wolffd@0: j = 0; wolffd@0: singul = 1; wolffd@0: ddd = []; wolffd@0: while j 1 wolffd@0: singul = 0; wolffd@0: elseif length(dd{j}) == 1 wolffd@0: ddd(end+1) = dd{j}; wolffd@0: end wolffd@0: end wolffd@0: if singul wolffd@0: dd = ddd; wolffd@0: end wolffd@0: end wolffd@0: if iscell(dd) wolffd@0: m{i} = {zeros(1,length(dd))}; wolffd@0: for j = 1:length(dd) wolffd@0: m{i}{1}(j) = mean(dd{j}); wolffd@0: end wolffd@0: elseif size(dd,2) < 2 wolffd@0: nonan = find(not(isnan(dd))); wolffd@0: dn = dd(nonan); wolffd@0: m{i}{1} = mean(dn,2); wolffd@0: else wolffd@0: %diffp = fp{i}{1}(1,2:end) - fp{i}{1}(1,1:end-1); wolffd@0: %if round((diffp(2:end)-diffp(1:end-1))*1000) wolffd@0: % Not regular sampling (in mirattacktime for instance) wolffd@0: % framesampling = NaN; wolffd@0: %else wolffd@0: % framesampling = fp{i}{1}(1,2)-fp{i}{1}(1,1); wolffd@0: %end wolffd@0: dd = mean(dd,4); wolffd@0: m{i} = {NaN(size(dd,1),1,size(dd,3))}; wolffd@0: for k = 1:size(dd,1) wolffd@0: for l = 1:size(dd,3) wolffd@0: dk = dd(k,:,l); wolffd@0: nonan = find(not(isnan(dk))); wolffd@0: if not(isempty(nonan)) wolffd@0: dn = dk(nonan); wolffd@0: m{i}{1}(k,1,l) = mean(dn,2); wolffd@0: end wolffd@0: end wolffd@0: end wolffd@0: end wolffd@0: end wolffd@0: m = mirscalar(f,'Data',m,'Title',['Average of ',ti]);