Function and Subfunction problem

조회 수: 1 (최근 30일)
Volker Kresser
Volker Kresser 2016년 3월 8일
답변: Walter Roberson 2016년 3월 9일
I have a question. Somehow I cant make the following functions work I know that I need in each n = length(x), but how can I do that?
function [gm,ra,hm] = arm_prop(x)
n = lenght(x); %send it to next funtion, but how
gm = gmean (n,x);
ra = rms (n,x);
hm = hmean (n,x);
end
function gm = gmean (n,x)
prd = 1;
for i = 1:n
prd = prd * x(i);
end
end
% A SUM MEANS I NEED A FOR LOOP!
function ra = rms (n,x)
sm = 0; %Initialize sum
for i = 1:n;
sm = sm + x(i)^2;
end
ra = sqrt(sm/n);
end
% Its again a Sum
function hm = hmean (n,x)
sm = 0;
for i = 1:n;
sm = sm/x(i);
end
hm = n/sm
end
  댓글 수: 1
per isakson
per isakson 2016년 3월 9일
What's the problem? Any error messages?
  • there is a typo in &nbsp n = lenght(x);
  • gm is not assigned a value in &nbsp gmean

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

답변 (1개)

Walter Roberson
Walter Roberson 2016년 3월 9일
You have
n = lenght(x); %send it to next funtion, but how
You need
n = length(x); %send it to next funtion, but how
lenght vs length

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by