필터 지우기
필터 지우기

Calling a function f inside f,how can we do this

조회 수: 1 (최근 30일)
Raviteja Panamgipalli
Raviteja Panamgipalli 2013년 4월 22일
function H=f(m)
H1=zeros(m/2);
H=[f(m/2) H1;H1 H1];
end

채택된 답변

Walter Roberson
Walter Roberson 2013년 4월 22일
편집: Walter Roberson 2013년 4월 22일
What you have will call f from inside f (which is called "recursion")
However, your code does not have any protections for the case that "m" is odd, and does not have any way to stop iterating when you get down to m == 1.
  댓글 수: 1
Raviteja Panamgipalli
Raviteja Panamgipalli 2013년 4월 22일
hey thanQ for your support,btw this is not the exact problem I have,btw it is some research paper,that's why couldn't write the exact one,but I found my mistake,I am returning a mx(2m) matrix instead of mxm,I tried to print another mxm matrix along with it,I corrected it, :),the question I was asking is about will matlab support recursion mechanism and I found that it actually do :)

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

추가 답변 (1개)

Babak
Babak 2013년 4월 22일
Just as a side issue: You better change the name of the function from a one letter name "f" to at least a 2 letter name. I remember I was trying to compute function of a function and MATLAB has issues (bugs) in calculating the result..(not sure if it's already fixed or not)... but things like sin(f(2)) or g(f(x)) may fail for a generic f function even if f is correctly defined.
This has nothing to do with the "recursion" Walter is talking about.
  댓글 수: 2
Raviteja Panamgipalli
Raviteja Panamgipalli 2013년 4월 23일
Okay,I'll see that I don't do that mistake,ThanQ :)
Walter Roberson
Walter Roberson 2013년 4월 23일
I have not heard of any issue with single-letter names. Do you have the bug report number, or a link to where you have posted about this before?

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

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by