Plot 10 times and take the average

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 :)

답변 (1개)

Jos (10584)
Jos (10584) 2016년 3월 24일

0 개 추천

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

N.
N. 2016년 3월 24일
I don't understand the tempV! Where is it initialized?
N.
N. 2016년 3월 24일
I want to make sure that you understand what i want to do! It's like i will loop on my Function 10 times for every element and get the average for every element in the users array
Jos (10584)
Jos (10584) 2016년 3월 24일
Does MyFunction(x) return a single number or a vector of 10 numbers?
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

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

태그

아직 태그를 입력하지 않았습니다.

질문:

N.
2016년 3월 24일

편집:

N.
2016년 3월 26일

Community Treasure Hunt

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

Start Hunting!

Translated by