[4] | 1 | function d = subsref(DataObj, index) |
---|
| 2 | % SUBSREF - Define field name indexing for AccObj objects |
---|
| 3 | % |
---|
| 4 | % Written by Greg Portmann |
---|
| 5 | |
---|
| 6 | |
---|
| 7 | if any(size(DataObj) > 1) |
---|
| 8 | % AccObj array |
---|
| 9 | d = DataObj(index.subs{:}); |
---|
| 10 | else |
---|
| 11 | d = DataObj; |
---|
| 12 | for i = 1:length(index) |
---|
| 13 | d = subsreflocal(d, index(i)); |
---|
| 14 | end |
---|
| 15 | end |
---|
| 16 | return |
---|
| 17 | |
---|
| 18 | |
---|
| 19 | function d = subsreflocal(DataObj, index) |
---|
| 20 | |
---|
| 21 | % 1 AccObj |
---|
| 22 | if ischar(index.subs) |
---|
| 23 | d = DataObj.(index.subs); |
---|
| 24 | return; |
---|
| 25 | end |
---|
| 26 | |
---|
| 27 | if isa(DataObj, 'AccObj') |
---|
| 28 | Families = fieldnames(DataObj); |
---|
| 29 | d = []; |
---|
| 30 | DeviceList = []; |
---|
| 31 | |
---|
| 32 | if iscell(index(1).subs{1}) |
---|
| 33 | % Find by device list |
---|
| 34 | for i = 1:length(Families) |
---|
| 35 | if iscell(index(1).subs{1}) |
---|
| 36 | % If index1 is a cell then it's a device list |
---|
| 37 | Index1 = findrowindex(index(1).subs{1}{1}, DataObj.(Families{i}).DeviceList); |
---|
| 38 | %if isempty(Index1) |
---|
| 39 | % error('??? Device not found.'); |
---|
| 40 | %end |
---|
| 41 | else |
---|
| 42 | Index1 = index.subs{1}; |
---|
| 43 | end |
---|
| 44 | Index2 = ':'; |
---|
| 45 | if length(index.subs) > 1 |
---|
| 46 | if iscell(index.subs{2}) |
---|
| 47 | Index2 = index.subs{2}; |
---|
| 48 | end |
---|
| 49 | end |
---|
| 50 | d = [d; DataObj.(Families{i}).Data(Index1,Index2)]; |
---|
| 51 | DeviceList = [DeviceList; DataObj.(Families{i}).DeviceList(Index1,:)]; |
---|
| 52 | end |
---|
| 53 | if isempty(d) |
---|
| 54 | error('??? Device not found.'); |
---|
| 55 | end |
---|
| 56 | % Should also error if an input device was not found anywhere??? |
---|
| 57 | else |
---|
| 58 | % Find by normal matlab indexing |
---|
| 59 | for i = 1:length(Families) |
---|
| 60 | d = [d; DataObj.(Families{i}).Data]; |
---|
| 61 | end |
---|
| 62 | d = d(index.subs{:}); |
---|
| 63 | end |
---|
| 64 | elseif isstruct(DataObj) |
---|
| 65 | |
---|
| 66 | if iscell(index(1).subs{1}) |
---|
| 67 | % Find by device list |
---|
| 68 | if iscell(index(1).subs{1}) |
---|
| 69 | % If index1 is a cell then it's a device list |
---|
| 70 | Index1 = findrowindex(index(1).subs{1}{1}, DataObj.DeviceList); |
---|
| 71 | if isempty(Index1) |
---|
| 72 | error('??? Device not found.'); |
---|
| 73 | end |
---|
| 74 | else |
---|
| 75 | Index1 = index.subs{1}; |
---|
| 76 | end |
---|
| 77 | Index2 = ':'; |
---|
| 78 | if length(index.subs) > 1 |
---|
| 79 | if iscell(index.subs{2}) |
---|
| 80 | Index2 = index.subs{2}; |
---|
| 81 | end |
---|
| 82 | end |
---|
| 83 | d = DataObj.Data(Index1,Index2); |
---|
| 84 | else |
---|
| 85 | Data = DataObj.Data; |
---|
| 86 | d = Data(index.subs{:}); |
---|
| 87 | end |
---|
| 88 | else |
---|
| 89 | d = DataObj(index.subs{:}); |
---|
| 90 | end |
---|
| 91 | return |
---|