This is a static copy of a profile reportHome
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)
Lines where the most time was spent
Line Number | Code | Calls | Total Time | % Time | Time Plot |
55 | d=d(x,:); | 78 | 0.306 s | 90.3% |  |
54 | d=getfield(s,char(names(i))); | 78 | 0.022 s | 6.5% |  |
56 | s=setfield(s,char(names(i)),d)... | 78 | 0.011 s | 3.2% |  |
57 | end | 78 | 0 s | 0% |  |
53 | for i=1:length(names) | 6 | 0 s | 0% |  |
All other lines | | | 0 s | 0% |  |
Totals | | | 0.339 s | 100% | |
Children (called functions)
Function Name | Function Type | Calls | Total Time | % Time | Time Plot |
setfield | function | 78 | 0.011 s | 3.2% |  |
getfield | function | 156 | 0.011 s | 3.2% |  |
Self time (built-ins, overhead, etc.) | | | 0.317 s | 93.5% |  |
Totals | | | 0.339 s | 100% | |
Code Analyzer results
Line number | Message |
40 | Assignment to 's' might be unnecessary. |
49 | The variable 'd' appears to change size on every loop iteration. Consider preallocating for speed. |
49 | Use dynamic fieldnames with structures instead of GETFIELD. |
52 | Use && instead of & as the AND operator in (scalar) conditional statements. |
54 | Use dynamic fieldnames with structures instead of GETFIELD. |
56 | Use dynamic fieldnames with structures instead of SETFIELD. |
59 | Use && instead of & as the AND operator in (scalar) conditional statements. |
61 | Use dynamic fieldnames with structures instead of GETFIELD. |
63 | Use dynamic fieldnames with structures instead of SETFIELD. |
Coverage results
[ Show coverage for parent directory ]
Total lines in function | 68 |
Non-code lines (comments, blank lines) | 39 |
Code lines (lines that can run) | 29 |
Code lines that did run | 11 |
Code lines that did not run | 18 |
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