Adding a standard deviation to the equation

1 回表示 (過去 30 日間)
Precious Benmaurice
Precious Benmaurice 2018 年 3 月 14 日
回答済み: NISARGA G K 2018 年 3 月 19 日
Hi,I'm trying to find the standard deviation from this function code that I've written for my mean, please how do I adjust it in order to find the standard deviation from the code I have written? I've tried a few codes but its not running.
function [ret] = mymean(a)
%UNTITLED Summary of this function goes here
% Detailed explanation goes here
len = length(a);
store=0;
for i=1:len
store=store+a(i);
end
ret = store / len;
end

回答 (1 件)

NISARGA G K
NISARGA G K 2018 年 3 月 19 日
I understand you want to find standard deviation of the vector. Add the following line to your code to obtain the same
standard_deviation = sqrt(sum((a - ret).^2)./(len-1))
Alternately, you can use mean and std functions in matlab

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by