필터 지우기
필터 지우기

Illegal use of 'end' in Simulink Coder when copying code from MATLAB to simulink function block

조회 수: 2 (최근 30일)
I have attached a picture to what I mean by this error. Any help would be appreciated on how I could overcome this error. This is usually how i code using the matlab coder but i think the matlab function in simulink doesn't accept a lot of syntax.
Thanks!

답변 (2개)

VBBV
VBBV 2022년 2월 1일
Remove the word end from brackets
  댓글 수: 3
Vishal Varadraj
Vishal Varadraj 2022년 2월 1일
Whats the difference between indexing the last value of an array and creating a new variable with just the last value of the array and using it for comparison? I managed to get past that error by using this in the mean time.
if PCMTemp < SampleTemperatureHeating(length(SampleTemperatureHeating))
VBBV
VBBV 2022년 2월 1일
SampleTemperatureHeating(length(SampleTemperatureHeating))
When you use length(yourarray) it gives largest value of array dimension. This means maximum number of elements in array. If you use in parenthesis () matlab will return the last value in that array. But this is usually not recommended as when your code gets larger, it becomes difficult to debug at later stage. That's why assign it to variable and call that variable inside the array.
K = length(SampleTemperatureHeating)
SampleTemperatureHeating(K)

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


Les Beckham
Les Beckham 2022년 2월 1일
It looks to me like the problem in that screenshot is a typo: "Heaating" vs. "Heating" in the variable name which you are trying to index with (end).
  댓글 수: 1
Vishal Varadraj
Vishal Varadraj 2022년 2월 1일
I fixed that typo and ended up still getting that error. I found a way around it. I just used this lol
if PCMTemp < SampleTemperatureHeating(length(SampleTemperatureHeating))

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

카테고리

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

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by