How could I fix the parsing error on line 8

조회 수: 22 (최근 30일)
Nuo
Nuo 2024년 1월 16일
이동: Dyuman Joshi 2024년 1월 16일
The following code gives a parsing error at <EOL> , usage might be invalid MATLAB syntax.

답변 (2개)

Dyuman Joshi
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')
The code ran without any error

Mann Baidi
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!

카테고리

Help CenterFile Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기

제품


릴리스

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by