Why this functions doesn't work on matlab coder
function [S,er]=somm1(n)
%n est le nombre de terme de la serie
S=0;
for x = 1:n
S=S+4*(-1)^(x-1)*(1/(2*x-1));
er=abs(S-pi)/pi;
end
It is saying that 'er' is not assigned on some exucution path.
How can I resolve this problem? Thank you

 채택된 답변

Guillaume
Guillaume 2016년 10월 17일

0 개 추천

If n is smaller than 1, the loop will not execute, hence er will never get created. Either assign a default value to er before the loop e.g.
er = nan;
for ...
or, if matlab coder supports it (I don't have it so don't know), issue an error before the loop if n is not valid:
if n < 1
error('nombre de termes doit etre au moins 1');
end
for ...

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 MATLAB Coder에 대해 자세히 알아보기

제품

태그

질문:

2016년 10월 17일

답변:

2016년 10월 17일

Community Treasure Hunt

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

Start Hunting!

Translated by