Cody

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

Solution 1605639

Submitted on 10 Aug 2018
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   Fail
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)

The "type" field in the indexing structure argument to SUBSREF and SUBSASGN must be a string scalar or character vector of "." or "{}" or "()". Error in Test1 (line 5) assert(isequal(subsref(b,subsdef(defstr)),y_correct) && nocheat)

2   Fail
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)

Dot indexing is not supported for variables of this type. Error in Test2 (line 5) assert(isequal(subsref(c,subsdef(defstr)),y_correct) && nocheat)

3   Fail
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)

The "type" field in the indexing structure argument to SUBSREF and SUBSASGN must be a string scalar or character vector of "." or "{}" or "()". Error in Test3 (line 5) assert(isequal(subsref(a,subsdef(defstr)),y_correct) && nocheat)

4   Fail
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)

The "type" field in the indexing structure argument to SUBSREF and SUBSASGN must be a string scalar or character vector of "." or "{}" or "()". Error in Test4 (line 5) 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!