Home > Software design >  Matlab: too many input arguments to strcmp
Matlab: too many input arguments to strcmp

Time:09-04

I have a data structure, and I'm trying to replace a char value within it. I'm using the following code: raw(1,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. raw(1,1).stimulus.values{1,1}.name

Returns: ans = 'stim_channel1'

order{1} returns ans = 'visff'

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? Thanks! Matlab R2021b, if it matters.

CodePudding user response:

When you execute the LHS alone, it uses the subsref method, which apparently can handle the multi-level indexing. However, it looks like the assignment method of that class subsasgn is not designed to handle multiple-level indexing.

You need either to fix Dictionary/subsasgn, or else split out the LHS so that you're doing only a simple assignment into the Dictionary.

Given that raw(1,1).stimulus is of the problematic Dictionary class, you need to ensure that you use on a single level of indexed assignment into that. In other words:

% Extract "values" from Dictionary
sv = raw(1,1).stimulus.values;
% Modify "values"
sv{1,1}.name = order{1};
% Put "values" back into Dictionary
raw(1,1).stimulus.values = sv;
  • Related