Cody

# Problem 2159. A SUBSREF variant that accepts the 'end'-operator.

Solution 398690

Submitted on 7 Feb 2014
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

### Test Suite

Test Status Code Input and Output
1   Pass
%% nocheat = isempty(regexp(evalc('type subsrefbetter'),'(eval|regexprep|inline|str2func)')); s.a.b(3).c{2}.d = 'a':'z'; def = substruct('.','a','.','b','()',{3},'.','c','{}',{2},'.','d','()',{1:3}); y = subsrefbetter(s,def); assert(isequal(y,'abc') && nocheat)

2   Fail
%% nocheat = isempty(regexp(evalc('type subsrefbetter'),'(eval|regexprep|inline|str2func)')); s.a.B(1).c{2}.d = 'a':'z'; def = substruct('.','a','.','B','()',{1},'.','c','{}',{2},'.','d','()',{'end'}); y = subsrefbetter(s,def); assert(isequal(y,'z') && nocheat)

Error: Assertion failed.

3   Pass
%% nocheat = isempty(regexp(evalc('type subsrefbetter'),'(eval|regexprep|inline|str2func)')); s.oz = magic(7); def = substruct('.','oz','()',{'end-1' 'end-2:7'}); y = subsrefbetter(s,def); assert(isequal(y,[43 3 12]) && nocheat)

4   Pass
%% nocheat = isempty(regexp(evalc('type subsrefbetter'),'(eval|regexprep|inline|str2func)')); [s(1:3).TiTa] = deal(magic(3)); def = substruct('()',{2},'.','TiTa','()',{':' ':'}); y = subsrefbetter(s,def); assert(isequal(y,magic(3)) && nocheat)

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!