How could I fix the parsing error on line 8
조회 수: 22 (최근 30일)
이전 댓글 표시
The following code gives a parsing error at <EOL> , usage might be invalid MATLAB syntax.
댓글 수: 0
답변 (2개)
Dyuman Joshi
2024년 1월 16일
이동: Dyuman Joshi
2024년 1월 16일
The most notable issue I can see is the un-supported character in the 8th line before the fix() call, which appears as a box.
Remove that character.
The code (turned into script from function and using the values present in the comments) runs without an error after removing that character -
%function [p, y]=comppoisson(tsim, lambda, mu,sigma, nrep, delta)
%simulate poisson process trajectories,normal jumps starting at zero
%output y: trajectories
% inputs: intensity parametrer, nosimulations, simulation time,
% delta:simulation interval
% mu, sigma: parameters jumps
tsim=1; lambda=5; mu=0.01; sigma=0.20; nrep=3; delta=1/365;
nint=fix(tsim/delta); %nro of intervals
NEV=zeros(nrep,nint);
CNEV=zeros(nrep,nint);
N=poissrnd(lambda*tsim,1,nrep);
y=zeros(nrep,nint);
p=zeros(nrep,nint);
ax=0:delta:1;
for k=1:nrep
JT=sort(tsim*rand(1,N(k)));
for j=1:nint
NEV(k,j)=length(JT((JT<j*delta)& (JT>=(j-1)*delta)));
if NEV(k,j)==0
CNEV(k,j)=0;
else
CNEV(k,j)=sum(normrnd(mu,sigma,1,NEV(k,j)));
end
end
p(k,:)=cumsum(NEV(k,:));
y(k,:)=cumsum(CNEV(k,:));
end
% plot(ax, [0 y])
%end
disp('The code ran without any error')
댓글 수: 0
Mann Baidi
2024년 1월 16일
Hi Nuo,
Assuming your are facing issue in running your function in MATLAB.
This is because there is an invalid character in your function code in line the "nint=fix(tsim/delta)" line of code.
It's possible that copying and pasting code from certain sources can introduce hidden characters that MATLAB does not recognize, leading to syntax errors or other unexpected behavior.
You can try rewriting the specific line of code again manually and then the code will work fine. This will ensure that any non-visible characters that might have been copied inadvertently are removed.
Thanks!
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!