필터 지우기
필터 지우기

Help defining a variable before subscripting it for Code Generation

조회 수: 8 (최근 30일)
Jess
Jess 2013년 3월 26일
답변: Navid Mohammadzadeh 2017년 11월 24일
Hi all,
Trying to rewrite some code so I can convert it into C using Matlab Coder.
Currently running into this error: "Code generation requires variable 'my variable' to be fully defined before subscripting it."
My code looks like this:
myvariable(1).name = 'John';
myvariable(1).value = something;
myvariable(1).number = 1;
myvariable(2).name = 'Tom';
myvariable(2).value = other_something;
myvariable(2).number = 1;
The suggestion given is to define myvariable before by either using zeros, repmat or struct, however doing that produces errors such as "Index exceeds matrix dimensions" or "Structure assignment to non-structure object". Any help would be appreciated!
  댓글 수: 1
Jess
Jess 2013년 3월 26일
After fiddling around, this seems to have done the trick:
myvariable = repmat(struct('name',[],'value',[],'number',[]),1,1);

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

답변 (1개)

Navid Mohammadzadeh
Navid Mohammadzadeh 2017년 11월 24일
Hi there!
I have this problem in my MATLAB Function Block. Let me know where do I have to put this line command in my Matlab code, Do I have to define it at very beginning?!
Regard

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by