필터 지우기
필터 지우기

Calling a function in another function

조회 수: 4 (최근 30일)
Haojie
Haojie 2012년 7월 10일
편집: Anmol Pardeshi 2018년 4월 8일
I am really new to matlab. When I wrote two functions like this:
funw.m
function q = funw(t)
h=0;
r=1/7;
q = quadl(@(x) sqrt(t^(2*r)-x.^(2*r)),h,t)...
-quadl (@(x) sqrt(x.^(2*r)-t^(2*r)),t,(h+2));
return
VentRate.m
function w = VentRate
global elev;
global h;
w = fzero(@funw,(h+elev)/2);
return
I try to use VentRate to call funw, by typing VentRate in the command window, but it will show some error. However, if i directly write w = fzero(@funw,(h+elev)/2) in the command window, it will run without error. So can anyone tell me what is wrong with the second function? I appreciate your help.

답변 (1개)

Anmol Pardeshi
Anmol Pardeshi 2018년 4월 8일
편집: Anmol Pardeshi 2018년 4월 8일
there are 2 pointers on this -
a. why are you keen on calling the funw function within a function; this is especially concerning because function ventRate does not take any input
b. the reason (i suspect this..not sure) for the error is because there is no input to the function. It is the way functions are built or the way their syntax is. No input field to a function may not be acceptable. Trying passing pseudo (fake or nonused) parameters to the ventRate function and see if it works.

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by