Cody

# Problem 988. Convert a substructure reference string into a valid definition structure for subsref and subsasgn

Solution 173665

Submitted on 6 Dec 2012 by @bmtran (Bryant Tran)
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 subsdef'),'(eval|regexprep|inline|str2func)')); y_correct = 1i; b(12) = y_correct; defstr = '(12)'; assert(isequal(subsref(b,subsdef(defstr)),y_correct) && nocheat)

2   Pass
%% nocheat = isempty(regexp(evalc('type subsdef'),'(eval|regexprep|inline|str2func)')); y_correct = -4i; c{1,2,3,4,5}.field_b = y_correct; defstr = '{1,2,3,4,5}.field_b'; assert(isequal(subsref(c,subsdef(defstr)),y_correct) && nocheat)

3   Pass
%% nocheat = isempty(regexp(evalc('type subsdef'),'(eval|regexprep|inline|str2func)')); y_correct = 3i; a(12).field_b{1,3}{2}((3),1).c = y_correct; defstr = '(12).field_b{1,3}{2}((3),1).c'; assert(isequal(subsref(a,subsdef(defstr)),y_correct) && nocheat)

4   Pass
%% nocheat = isempty(regexp(evalc('type subsdef'),'(eval|regexprep|inline|str2func)')); y_correct = repmat(2i,3,1); d{2}.a(1:3,:) = y_correct; defstr = '{2}.a(1:3,:)'; assert(isequal(subsref(d,subsdef(defstr)),y_correct) && nocheat)

### Community Treasure Hunt

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

Start Hunting!