필터 지우기
필터 지우기

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

조회 수: 13 (최근 30일)
Darshan Gade
Darshan Gade 2021년 4월 14일
답변: Walter Roberson 2021년 4월 14일
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
Daniel Pollard
Daniel Pollard 2021년 4월 14일
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.

댓글을 달려면 로그인하십시오.

채택된 답변

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Structures에 대해 자세히 알아보기

제품


릴리스

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by