Effacer les filtres
Effacer les filtres

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

9 vues (au cours des 30 derniers jours)
Darshan Gade
Darshan Gade le 14 Avr 2021
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 commentaire
Daniel Pollard
Daniel Pollard le 14 Avr 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.

Connectez-vous pour commenter.

Réponse acceptée

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

Plus de réponses (0)

Catégories

En savoir plus sur Structures dans Help Center et File Exchange

Produits


Version

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by