Adding legends for a plot in matlab function block.

조회 수: 2 (최근 30일)
Charan
Charan 2024년 1월 18일
이동: Fangjun Jiang 2024년 1월 23일
i wanted to add a legend to the plot which is the output from matlab function block, but im ending up with an error as "Function 'legend' not supported for code generation." so can anyone help me out to add this legend function in matlab function block.
function [mean, stdev] = stats(vals)
len = length(vals);
mean = avg(vals,len);
stdev = sqrt(sum(((vals-avg(vals,len)).^2))/len);
plot(vals,"-+");
legend("Autoupdate","off")
end
  댓글 수: 4
Adam Danz
Adam Danz 2024년 1월 22일
Right after receiving this error, could you run the following 2 lines of code and share the content each line produces? Also, please let me now what MATLAB release you're using.
S = lasterror
S.stack
Fangjun Jiang
Fangjun Jiang 2024년 1월 22일
The error is reported by Simulink during model compile. The code has not been able to be executed yet.

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

답변 (1개)

Fangjun Jiang
Fangjun Jiang 2024년 1월 18일
편집: Fangjun Jiang 2024년 1월 18일
There is a way to deal with this type of error.
However, are you sure you want to do this? Because the MATLAB Function block in a Simulink model usually is executed at every simulation step.
This recent Q&A might give you a better idea.
  댓글 수: 1
Charan
Charan 2024년 1월 23일
이동: Fangjun Jiang 2024년 1월 23일
thanks for the answer , i was able to solve the above error by passing the legend as an extrinsic function inside a matlab function block.
coder.extrinsic('legend')

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

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by