Since all of my "Undefined function or variable" errors were on variables, and all my variables were 1 x 1 doubles, I just defined them all as 0 prior to them being defined in a for loop. It seems you can not define them in a for loop.
"Undefined function or variable '****'. The first assignment to a local variable determines its class."
조회 수: 204 (최근 30일)
이전 댓글 표시
Hi all,
I'm using Coder to convert my code to C/C++.When I attempt to convert one of my functions just for practice, i started receiving errors. I was unsure how to define my inputs, so I used stops and discovered my input was a struct. The fields in that input I was able to define mostly as double(1x1) (determined by using stops again) as well as one of the fields being a struct as well. Now the error I get when I tryto build my code is
Undefined function or variable 'DopplerSpread'. The first assignment to a local variable determines its class.
What am I doing wrong? Do I need to define each function prior to using it in my code? Below is a sample of the line of code receiving that error.
DopplerSpread(path_ct) = FadeAll.Subpaths(path_ct).DopplerSpread;
댓글 수: 0
채택된 답변
Adam Kaas
2012년 5월 23일
댓글 수: 2
Walter Roberson
2019년 5월 26일
편집: Walter Roberson
2019년 5월 26일
Yes, but Nam moon Kim's solution is better: https://www.mathworks.com/matlabcentral/answers/39191-undefined-function-or-variable-the-first-assignment-to-a-local-variable-determines-its-clas#answer_338798
추가 답변 (5개)
Nam moon Kim
2018년 9월 28일
편집: Nam moon Kim
2018년 9월 28일
I had a same problem. I think that is variable initiation problem.
in the matlab, if there is not variable, that's variable auto generation. however, in the stateflow, need a initiation.
in my case
*********************** error **********************
function ~
for i=1:len
temp(i) = i;
end
end
*********************** not error ******************
function ~
temp = zeros(len,1);
for i=1:len
temp(i) = i;
end
end
댓글 수: 1
Nick
2021년 7월 9일
Do you know what to do if the variable that is giving me an error is an input to the function and is needed in an if statement?
Sana Ben Hmouda
2017년 7월 26일
Hello everybody, The answer of Adam Kaas was very clear. Azza al-abri you need only to initialize the concerned variable at 0. (i.e if your variable is varia, so you put varia=0; before the loop starts)
댓글 수: 0
Aaditya Umasankar
2021년 11월 24일
Hello everybody, in mining truck shovel operation,the truck takes some load from escavator to crusher(unloads) and come back to escavator to load and again unloads it at crusher,and this process continues till shift time ends so how do we loop the entity generator(number of trucks,truck capacity are enity attributes)) with enity server(escavator and crusher) , for this which type of block shall be used to solve the problem(simevents)
댓글 수: 2
SOUVIK BASAK
2022년 7월 17일
Please ask your doubt somewhere else. This is not related to discussion in this thread
참고 항목
카테고리
Help Center 및 File Exchange에서 Generating Code에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!