how to use input element of function in code?

조회 수: 1 (최근 30일)
moonman
moonman 2011년 10월 6일
Let's suppose I have this function
function [mean,stdev] = stat(x,b)
n = length(x)
mean = sum(x)/n;
stdev = sqrt(sum((x-mean).^2/b));
and I call this function by
>> [mean stdev] = stat([12.7 45.4 98.9 26.6 53/1],400)
Is there any way I can use each element of input in my code lets suppose in my code I want to use sum which is equal to first element + second element (that is 12.7+45.4)
sum = input_element_1 + input_element_2
How can I do that?
  댓글 수: 1
Sean de Wolski
Sean de Wolski 2011년 10월 6일
DON'T NAME YOUR VARIABLE 'MEAN'!!!!!
(5 exclamation points oughtta do it)
mean is a very useful function and it's terrible practive to overwrite it.

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

채택된 답변

Fangjun Jiang
Fangjun Jiang 2011년 10월 6일
Inside your function, just use y=x(1)+x(2). It is a good idea to check the size of x first.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by