Filter löschen
Filter löschen

How could I fix the parsing error on line 8

6 Ansichten (letzte 30 Tage)
Nuo
Nuo am 16 Jan. 2024
Verschoben: Dyuman Joshi am 16 Jan. 2024
The following code gives a parsing error at <EOL> , usage might be invalid MATLAB syntax.

Antworten (2)

Dyuman Joshi
Dyuman Joshi am 16 Jan. 2024
Verschoben: Dyuman Joshi am 16 Jan. 2024
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 am 16 Jan. 2024
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!

Kategorien

Mehr zu Debugging and Analysis finden Sie in Help Center und File Exchange

Produkte


Version

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by