How to calculate the coefficient of variation in Matlab

조회 수: 75 (최근 30일)
Xuefei Sun
Xuefei Sun 2021년 2월 22일
편집: dpb 2021년 8월 11일
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
dpb 2021년 2월 23일
편집: dpb 2021년 8월 11일
N=30;
mn=mean(reshape([time(:),speed(:)],N,[]));
sd=std(reshape([time(:),speed(:)],N,[]));
cv=reshape(sd./mn,[],N);
returns CV of time, speed as columns in cv.
  댓글 수: 4
Katharina Hofer
Katharina Hofer 2021년 8월 11일
Shouldn't it be std divided by the mean, not mean divided by the std?
dpb
dpb 2021년 8월 11일
Indeed. Good catch, @Katharina Hofer

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by