How could I fix the parsing error on line 8
23 次查看(过去 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 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!