Plot 10 times and take the average

5 visualizaciones (últimos 30 días)
N.
N. el 24 de Mzo. de 2016
Editada: N. el 26 de Mzo. de 2016
Hello,
users = [10 20 30 40 50];
rates = [];
for i = 1 : length(users)
rates = [rates Function(users(i))];
end
figure(3)
plot(users,rates)
I have this code that calls another function 'Function' This function calculates the rates that i want to plot, but what i want to do is that for 10 users i want to plot the rates for 10 times and take the average and plot, the same goes with the 20, 30, 40 and 50 users. I want to plot every element in the array 'users' versus 'rates' which is calculated in another function 10 times and take the average of every 10 times and put the result of the 5 elements in a plot. Can anyone help?
Thank you :)

Respuestas (1)

Jos (10584)
Jos (10584) el 24 de Mzo. de 2016
users = [10 20 30 40 50];
N = numel(users) ;
rates = zeros(1,N) ; % pre_allocation
for i = 1 : N
tempV = MyFunction(users(i)) ; % assuming V is vector of 10 elements?
rates(i) = mean(tempV)
end
plot(users,rates,'bo')
  4 comentarios
Jos (10584)
Jos (10584) el 24 de Mzo. de 2016
Does MyFunction(x) return a single number or a vector of 10 numbers?
Jos (10584)
Jos (10584) el 24 de Mzo. de 2016
You can create an inner loop:
for i = ...
tempV = zeros(1,10) ;
for k = 1:10
tempV(k) = MyFunction(users(i))
end
rates(i) = mean(tempV)
end

Iniciar sesión para comentar.

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Etiquetas

Aún no se han introducido etiquetas.

Community Treasure Hunt

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

Start Hunting!

Translated by