MATLAB: How to find value parameter in command window from m file matlab

matlab function

how to find w0 value at command window from my m-file function below?
function Pfit=VarProb(p);
w0=p(1);
x(1)=1.15;
%Calculation of fit by constant probability w0;
L=length(p);Pfit(1)=w0;pfit(1)=w0;
for k=2:L;
pfit(k)=pfit(k-1)*x(1)*(1-(x(1)^(k-2)*w0…
end;
for k=2:L;
Pfit(k)=Pfit(k-1)+pfit(k);
end;
Additional Details
i type w0 at command window nothing appear.

Best Answer

Edit your code as follows, you missed two close brackets in the pfit(k) line
function Pfit=VarProb(p);
w0=p(1)
x(1)=1.15;
%Calculation of fit by constant probability w0;
L=length(p);Pfit(1)=w0;pfit(1)=w0;
for k=2:L;
pfit(k)=pfit(k-1)*x(1)*(1-(x(1)^(k-2)*w0)) % this is edited line
end
for k=2:L;
Pfit(k)=Pfit(k-1)+pfit(k);
end
Now save the function as VarProb.m
and run it from the command line as follows
>> VarProb([0.2,0.4])
w0 =
0.20
pfit =
0.20 0.18
ans =
0.20 0.38
Related Question