How to create a cumulative frequency array

I am trying to create an array to compute the cumulative frequency of array Z, which are less than or equal to the time in minutes specified by the minutes array, V.
X1= sqrt(rand(1,1000));
X2= normrnd(20,5, 1,1000);
w= rand(1,1000);
X3 = (-log(1- w));
sz = [1 1000];
X4 = unifrnd(4,15, sz);
Z=X1+X2+X3+X4; %(note: Z is an array with 1000 values in one row)
V = linspace(1, 1000, 1000); %array V

 Respuesta aceptada

Jeff Miller
Jeff Miller el 28 de Abr. de 2021
This is inelegant, but it works:
cumFreq = zeros(size(V));
for i=1:numel(V)
cumFreq(i) = sum(Z<V(i));
end

5 comentarios

so this computes the frequency per location in array??
Thanks!! i will try it out
BigWaffle
BigWaffle el 29 de Abr. de 2021
This does not seem to give me cumulative frequency per trials. like if there was 3 values in Y array that are less than V array then when it finds 3rd that fits logic it will give me 3 in new array. Freq+1+1+1 because logic has be fulfilled 3 times.
hope im explaining it well
Jeff Miller
Jeff Miller el 30 de Abr. de 2021
No, sorry, I guess I misunderstood the problem. Maybe a small numerical illustration would help make it clear what you are trying to count?
so this is what i ended up with after many attempts
im trying to get frequency at each time step (V) for Z
V = linspace(1,1000,1000);
j = 1;
while sum(Y > V(j))>0
for j=j+1
freq(j) = sum(Z <= V(j));
end
end
BigWaffle
BigWaffle el 30 de Abr. de 2021
thanks to your guidance. it was working just needed a tweak

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Get Started with MATLAB en Centro de ayuda y File Exchange.

Productos

Preguntada:

el 28 de Abr. de 2021

Comentada:

el 30 de Abr. de 2021

Community Treasure Hunt

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

Start Hunting!

Translated by