Error trying to change char value, too many inputs

5 views (last 30 days)
I have a data structure, and I'm trying to replace a char value within it.
I'm using the following code:
raw(subj,1).stimulus.values{1,1}.name=order{1};
If I run either side of this on its own, I get a single string of class char in return.
But if I run the whole thing, I get the following error:
Error using strcmp
Too many input arguments.
Error in Dictionary/subsasgn (line 233)
if strcmp(s.type,'()')
But I'm trying to replace a single string with another single string. How is this too many arguments?
What am I doing wrong?
  4 Comments
Walter Roberson
Walter Roberson on 2 Sep 2022
R2021b does not have any class named Dictionary that I can recall. You are invoking an assignment method for a class named Dictionary
Henry Brice
Henry Brice on 2 Sep 2022
Ah, this seems to be a bug with the custom class that is part of the toolbox I'm using. Thanks for your help getting to the bottom of this!

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 2 Sep 2022
Consider what happens if you have a non-scalar struct or object reference A.B.C and suppose the class does not implement subsref or subsasgn itself.
If it were the A level that was nonscalar then MATLAB would normally complain about not being able to index a nonscalar.
If it were the B level that was nonscalar and this was in the context of something that returned an expression then you would get struct expansion. Suppose for example A.B(1).C was a character vector then you would get its value displayed at the command window and A.B(2).C and the rest would be discarded unless it was in a context that captured the values such as {A.B.C}. So when you ask for display and get back a single character vector that does not prove that you are working with a scalar reference.
In your code values{1,1} could expand to a struct or object array.
When a class that implements subsref is thrown in, it is permitted to override the behaviour of generating an error for indexing a nonscalar, so in theory the difficulty could be further up. And might do so accidentally by the subsequent method for the class not having been designed with nonscalar in mind.
Then when you get to a class subsasgn method, the code might neglect to test for nonscalar and end up with the kind of message you saw.

More Answers (0)

Categories

Find more on Structures in Help Center and File Exchange

Tags

Products


Release

R2021b

Community Treasure Hunt

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

Start Hunting!