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

14 visualizzazioni (ultimi 30 giorni)
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 Commento
Daniel Pollard
Daniel Pollard il 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.

Accedi per commentare.

Risposta accettata

Walter Roberson
Walter Roberson il 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.

Più risposte (0)

Categorie

Scopri di più su Structures in Help Center e File Exchange

Prodotti


Release

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by