root/branches/telle/v2.00-at/mfiles/@NXTmotor/subsref.m @ 390

Revision 390, 2.8 KB (checked in by telle, 5 years ago)

Added NXTmotor class (works for standard NXT DirectCommands?)

Line 
1function result = subsref(obj, Struct)
2%SUBSREF Subscripted reference into NXTmotor objects.
3%
4%   SUBSREF Subscripted reference into NXTmotor objects.
5%
6%   OBJ.PROPERTY returns the property value of PROPERTY for motorsetting
7%   object OBJ.
8%
9%   Supported syntax for NXTmotor objects:
10%
11%   Dot Notation:                  Equivalent Get Notation:
12%   =============                  ========================
13%   obj.Prop                       get(obj, 'Prop')
14%   obj(k).Prop                    get(obj(k), 'Prop')
15%   obj(k)
16
17% Signature
18%   Author: Aulis Telle (see AUTHORS)
19%   Date: 2008/08/15
20%   Copyright: 2007-2008, RWTH Aachen University
21%
22%
23% ***********************************************************************************************
24% *  This file is part of the RWTH - Mindstorms NXT Toolbox.                                    *
25% *                                                                                             *
26% *  The RWTH - Mindstorms NXT Toolbox is free software: you can redistribute it and/or modify  *
27% *  it under the terms of the GNU General Public License as published by the Free Software     *
28% *  Foundation, either version 3 of the License, or (at your option) any later version.        *
29% *                                                                                             *
30% *  The RWTH - Mindstorms NXT Toolbox is distributed in the hope that it will be useful,       *
31% *  but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS  *
32% *  FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.             *
33% *                                                                                             *
34% *  You should have received a copy of the GNU General Public License along with the           *
35% *  RWTH - Mindstorms NXT Toolbox. If not, see <http://www.gnu.org/licenses/>.                 *
36% ***********************************************************************************************
37
38if ~isa(obj,'NXTmotor')
39    error('MATLAB:RWTHMindstormsNXT:InvalidObject',...
40        'No NXTmotor object.');
41end
42
43result = obj;
44
45StructLength = length(Struct);
46
47if StructLength > 2
48    error('RWTHMINDSTORMS:motor:unsupportedSubscript','Too deep subscription');
49end
50
51if StructLength == 2
52    if (strcmp(Struct(1).type,'()') == 0) || (strcmp(Struct(2).type,'.') == 0)
53        error('RWTHMINDSTORMS:motor:unsupportedSubscript','Unsupported subscription');       
54    end
55
56    Index = Struct(1).subs{:};
57    result = get(obj(Index), Struct(2).subs);
58else
59    if strcmp(Struct(1).type,'.')
60        result = get(obj, Struct(1).subs);
61    elseif strcmp(Struct(1).type,'()')
62        result = obj(Struct(1).subs{:});
63    else
64        error('RWTHMINDSTORMS:motor:unsupportedSubscript','Unsupported subscription');       
65    end
66end
Note: See TracBrowser for help on using the browser.