Input #2 expected to be a cell array, was struct instead.

14 views (last 30 days)
Can anyone tell what is the issue here
>> {MISRAErrorTables(fl).Table(tl).Line}
ans =
1×1 cell array
{'29'}
>> x = Code2Model
x =
struct with fields:
token: [1×1 struct]
file: [1×1 struct]
line: [1×1 struct]
begin: [1×1 struct]
sidlink: [1×1 struct]
>> {x.line.Text}
ans =
1×1 cell array
{'29'}
>> {x.file.Text}
ans =
1×1 cell array
{'Generic20kHzModule_ac.c'}
>> {[ModelName,'_ac.c']}
ans =
1×1 cell array
{'Generic20kHzModule_ac.c'}
>> LineIndex{tl} = find(cell2mat(cellfun(@(x)(strcmp({x.line.Text},{MISRAErrorTables(fl).Table(tl).Line})...
&& strcmp({x.file.Text},{[ModelName,'_ac.c']})),Code2Model,'UniformOutput',false)))
Error using cellfun
Input #2 expected to be a cell array, was struct instead.
  1 Comment
Daniel Pollard
Daniel Pollard on 14 Apr 2021
Please format your code properly. Explain what the code does and how you expected it to work. I tried reading through what's there but it makes no sense to someone who's not you, and we can't run it because you haven't defined any of the variables.
As it happens, "Input #2 expected to be a cell array, was struct instead." is a very descriptive error message. The function expected the second input to be a cell array. You gave it a structure instead. The code errored. Since you don't explain the code, the inputs or the expected outputs, no one can help you.

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 14 Apr 2021
You need arrayfun() instead of cellfun() for that purpose.
This assumes that in time Code2Model will be a non-scalar struct array.

More Answers (0)

Categories

Find more on Structures in Help Center and File Exchange

Products


Release

R2018b

Community Treasure Hunt

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

Start Hunting!