# How to calculate the coefficient of variation in Matlab

453 views (last 30 days)
Xuefei Sun on 22 Feb 2021
Commented: Xuefei Sun on 23 Feb 2021
I have 90000 time data and 90000 speed data, and the time are equally averaged. I need to calculate the coefficient of variation for every 30 sec and plot it.
Here is my code, and I got 3000*3000 for the coefficient of variation. So I cannot plot it. Does anyone know how to fix it?
a=time;
b=speed;
n=30;
time_aver=reshape(a,n,[]);
speed_aver=mean(reshape(b,n,[]));
%
time_std=reshape(a,n,[]);
speed_std=std(reshape(b,n,[]));
%
speed_CV=speed_std\speed_aver;
plot(time_aver,speed_aver,'LineWidth',2);
hold on
plot(time_std,speed_std,'LineWidth',2);

dpb on 23 Feb 2021
N=30;
mn=mean(reshape([time(:),speed(:)],N,[]));
sd=std(reshape([time(:),speed(:)],N,[]));
cv=reshape(mn./sd,[],N);
returns CV of time, speed as columns in cv.
##### 2 CommentsShowHide 1 older comment
Xuefei Sun on 23 Feb 2021
I got what you mean. What I need is add a dot behind the molecular. Now I can get the answer. Thank you!