Cody

Solution 1685218

Submitted on 3 Dec 2018 by Binbin Qi
  • Size: 116
  • This is the leading solution.
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   Pass
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)

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)