How to fix this error " Search term must be a string array, character vector, or cell array of character vectors", I got this error when I used N = count(s,t);
27 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
%For example: Generate a sample path of N(t ), a rate λ = 5 arrivals/min Poisson process. Plot N(t ) over a 10-minute interval.
.............................................
clear all;
clc;
t = 0.01*(0:1000);
lambda = 5;
N = poissonprocess(lambda,t);
plot(t,N)
xlabel('\it t');
ylabel('\it N(t)');
function N = poissonprocess(lambda,t)
%input: rate lambda>0, vector t For a sample function of a
%Poisson process of rate lambda, N(i) = no. of arrivals by t(i)
s = poissonarrivals(lambda,max(t)); %poissonarrivals returns the vector s with s(i) corresponding to Si , the
%ith arrival time.
N = count(s,t); % N(t ) = max {n|Sn ≤ t}, is the number of arrivals that occur by time t
%which counts the number of elements of s that are less than or equal to t(i)
%for each t(i).
end
function s = poissonarrivals(lambda,T)
%Arrival times s=[s(1) ... s(n)], s(n) <= T < s(n+1)
n = ceil(1.1*lambda*T);
s = cumsum(exponentialrv(lambda,n));
while (s(length(s))< T)
s_new = s(length(s))+ ...
cumsum(exponentialrv(lambda,n));
s =[s; s_new];
end
s = s(s<=T);
end
function x = exponentialrv(lambda,m)
x = -(1/lambda)*log(1-rand(m,1));
end
6 Kommentare
Walter Roberson
am 6 Dez. 2021
hint: make s a column vector and t a row vector, and use <= between those, and sum() along the first dimension
Antworten (0)
Siehe auch
Kategorien
Mehr zu Matrices and Arrays finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!