annotate toolboxes/MIRtoolbox1.3.2/MIRToolbox/mirstd.m @ 0:e9a9cd732c1e tip

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