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