This is a static copy of a profile report

Home

structcut (6 calls, 0.339 sec)
Generated 05-Aug-2011 13:03:48 using cpu time.
function in file /home/LeechJ/cbass_analysis/matutils/structcut.m
Copy to new window for comparing multiple runs

Parents (calling functions)

Function NameFunction TypeCalls
overfWrapperfunction2
packdfunction4
Lines where the most time was spent

Line NumberCodeCallsTotal Time% TimeTime Plot
55
d=d(x,:);
780.306 s90.3%
54
d=getfield(s,char(names(i)));
780.022 s6.5%
56
s=setfield(s,char(names(i)),d)...
780.011 s3.2%
57
end
780 s0%
53
for i=1:length(names)
60 s0%
All other lines  0 s0%
Totals  0.339 s100% 
Children (called functions)

Function NameFunction TypeCallsTotal Time% TimeTime Plot
setfieldfunction780.011 s3.2%
getfieldfunction1560.011 s3.2%
Self time (built-ins, overhead, etc.)  0.317 s93.5%
Totals  0.339 s100% 
Code Analyzer results
Line numberMessage
40Assignment to 's' might be unnecessary.
49The variable 'd' appears to change size on every loop iteration. Consider preallocating for speed.
49Use dynamic fieldnames with structures instead of GETFIELD.
52Use && instead of & as the AND operator in (scalar) conditional statements.
54Use dynamic fieldnames with structures instead of GETFIELD.
56Use dynamic fieldnames with structures instead of SETFIELD.
59Use && instead of & as the AND operator in (scalar) conditional statements.
61Use dynamic fieldnames with structures instead of GETFIELD.
63Use dynamic fieldnames with structures instead of SETFIELD.
Coverage results
[ Show coverage for parent directory ]
Total lines in function68
Non-code lines (comments, blank lines)39
Code lines (lines that can run)29
Code lines that did run11
Code lines that did not run18
Coverage (did run/can run)37.93 %
Function listing
   time   calls  line
1 function s=structcut(s,x)
2 % structure=structcut(structure,i)
3 %
4 % I find I often want to shrink a structure
5 % of the form
6 %
7 % s.a(n)
8 % s.b(n)
9 % s.c(n)
10 %
11 % according to some matrix of indices i.
12 % For example it's a pain to do:
13 %
14 % x=s.a>1;
15 % s.a=s.a(x);
16 % s.b=s.b(x);
17 % s.c=s.c(x);
18 %
19 % and if I add another field I have to change
20 % the code in multiple places.
21 %
22 % This function automatically cuts all fields
23 % so the code becomes:
24 %
25 % x=s.a>1;
26 % s=structcut(s,x);
27 %
28 % and continues to work if fields are added.
29 %
30 % Now extended so that fields can be 2D - will try to figure
31 % out which dimension to cut over by looking for the dim which is
32 % equal length for all fields. If all are same cut will occur over
33 % rows.
34
35 % first let's check if it even needs to be cut.
6 36 if(length(x)==1)
37 if(x==0)
38 s = [];
39 else
40 s = s;
41 end
42 return;
43 end
44
6 45 names=fieldnames(s);
46
47 % Get sizes of fields
6 48 for i=1:length(names)
78 49 d(i,:)=size(getfield(s,char(names(i))));
78 50 end
51
6 52 if(all(d(:,1)==d(1,1)) & d(1,1)~=1)
6 53 for i=1:length(names)
0.02 78 54 d=getfield(s,char(names(i)));
0.31 78 55 d=d(x,:);
0.01 78 56 s=setfield(s,char(names(i)),d);
78 57 end
58 else
59 if(all(d(:,2)==d(1,2)) & d(1,2)~=1)
60 for i=1:length(names)
61 d=getfield(s,char(names(i)));
62 d=d(:,x);
63 s=setfield(s,char(names(i)),d);
64 end
65 else
66 error('Dont know which array dim to cut over');
67 end
68 end