필터 지우기
필터 지우기

Syntax help with script

조회 수: 3 (최근 30일)
Greg
Greg 2013년 6월 20일
I am wanting to put this equation into matlab, but I am having problems.
I am wanting to find the standard deviation without the built in matlab function. I have a mean_temp and a mean_pres already set up and displaying properly. Can I get some help how to incorporate those values (i have i=1:30) for each temp and pressure.
The standard deviation equation is:
(sum i=1 to n (xi^2-nxbar^2))/(n-1)
My xi should be my values each 1 through 30. xbar is my mean.
Thank you in advance.

채택된 답변

John
John 2013년 6월 20일
assuming x is an nx1 column vector...
sum(x.^2-mean(x)^2)/size(x,1)
also I think your equation is wrong: http://en.wikipedia.org/wiki/Standard_deviation you'll want to square after subtracting, not before.
sum((x-mean(x)).^2)/size(x,1)

추가 답변 (1개)

Greg
Greg 2013년 6월 20일
You are correct, I had entered the equation wrong. Thanks. For your response, when I am substituting my variable for yours, can I enter display value as x?
Here is some of the code that I am trying to work with. Does the code you provided above operate for each of my i values or just for the mean that is calculated?
------------------------------------
sum_temp=0; sum_pres=0;
% Mean value of Temperature
for i=1:length(temperature) sum_temp=sum_temp+temperature(i); end mean_temp=sum_temp/length(temperature)
% Mean value of Pressure
for i=1:length(pressure) sum_pres=sum_pres+pressure(i); end mean_pres=sum_pres/length(pressure)
% Standard deviation Value of Temperature
  댓글 수: 1
John
John 2013년 6월 20일
oh sorry, I was assuming i was the length of your vector x. If you want the standard deviation of "temperature", then you would just do:
sum((temperature-mean(temperature)).^2)/size(temperature,1)
assuming temperature has i rows and 1 column. No for-loop is necessary.

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

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by