annotate toolboxes/MIRtoolbox1.3.2/MIRToolbox/mirstd.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 = mirstd(f,varargin)
Daniel@0 2 % m = mirstd(f) returns the standard deviation 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} = mirstd(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) = mirstd(f.(field));
Daniel@0 18 end
Daniel@0 19 varargout = {stat};
Daniel@0 20 else
Daniel@0 21
Daniel@0 22 normdiff.key = 'NormDiff';
Daniel@0 23 normdiff.type = 'Boolean';
Daniel@0 24 normdiff.default = 0;
Daniel@0 25 specif.option.normdiff = normdiff;
Daniel@0 26
Daniel@0 27 specif.nochunk = 1;
Daniel@0 28
Daniel@0 29 varargout = mirfunction(@mirstd,f,varargin,nargout,specif,@init,@main);
Daniel@0 30 end
Daniel@0 31
Daniel@0 32
Daniel@0 33 function [x type] = init(x,option)
Daniel@0 34 type = '';
Daniel@0 35
Daniel@0 36
Daniel@0 37 function m = main(f,option,postoption)
Daniel@0 38 if iscell(f)
Daniel@0 39 f = f{1};
Daniel@0 40 end
Daniel@0 41 if isa(f,'mirhisto')
Daniel@0 42 warning('WARNING IN MIRSTD: histograms are not taken into consideration yet.')
Daniel@0 43 m = struct;
Daniel@0 44 return
Daniel@0 45 end
Daniel@0 46 fp = get(f,'FramePos');
Daniel@0 47 ti = get(f,'Title');
Daniel@0 48 d = get(f,'Data');
Daniel@0 49 l = length(d);
Daniel@0 50 for i = 1:l
Daniel@0 51 if iscell(d{i})
Daniel@0 52 if length(d{i}) > 1
Daniel@0 53 error('ERROR IN MIRSTD: segmented data not accepted yet.');
Daniel@0 54 else
Daniel@0 55 dd = d{i}{1};
Daniel@0 56 end
Daniel@0 57 else
Daniel@0 58 dd = d{i};
Daniel@0 59 end
Daniel@0 60 if iscell(dd)
Daniel@0 61 m{i} = {zeros(1,length(dd))};
Daniel@0 62 for j = 1:length(dd)
Daniel@0 63 m{i}{1}(j) = std(dd{j});
Daniel@0 64 end
Daniel@0 65 elseif size(dd,2) < 2
Daniel@0 66 nonan = find(not(isnan(dd)));
Daniel@0 67 dn = dd(nonan);
Daniel@0 68 if option.normdiff
Daniel@0 69 m{i}{1} = norm(diff(dn,2));
Daniel@0 70 else
Daniel@0 71 m{i}{1} = std(dn,0,2);
Daniel@0 72 end
Daniel@0 73 else
Daniel@0 74 dd = mean(dd,4);
Daniel@0 75 m{i} = {NaN(size(dd,1),1,size(dd,3))};
Daniel@0 76 for k = 1:size(dd,1)
Daniel@0 77 for l = 1:size(dd,3)
Daniel@0 78 dk = dd(k,:,l);
Daniel@0 79 nonan = find(not(isnan(dk)));
Daniel@0 80 if not(isempty(nonan))
Daniel@0 81 dn = dk(nonan);
Daniel@0 82 if option.normdiff
Daniel@0 83 m{i}{1}(k,1,l) = norm(diff(dn,2));
Daniel@0 84 else
Daniel@0 85 m{i}{1}(k,1,l) = std(dn,0,2);
Daniel@0 86 end
Daniel@0 87 end
Daniel@0 88 end
Daniel@0 89 end
Daniel@0 90 end
Daniel@0 91 end
Daniel@0 92 m = mirscalar(f,'Data',m,'Title',['Standard deviation of ',ti]);