Hi,
I want to create a function that calculates a equation, say for example
function [n] = ns(dBcalc,wave, zL)
n = @(dBcalc,wave,zL) log(10^(dBcalc/10))/((4*pi*zL)/wave);
end
but when I try to call this by ns(14,765e-9,e-2) it does not work. I get error saying I get to many output arguments or calling the function it simply gives back the function (i.e. it prints the function n ) not the value.
I tried to also removed the @(dBcalc,wave,zL) but still I get errors. I tried some basic equation and that works but not this. Not sure where the mistake comes from?

댓글 수: 4

Oleg Komarov
Oleg Komarov 2012년 5월 30일
It is expected to return the anonymous function because 'function ns()' just defines the function but does not execute the operations.
Lizan
Lizan 2012년 5월 30일
Sorry I accidentally wrote wrong: you call the function with for example ns(-32.1,785e-9,1e-2) but it still does not work when I place thus code in a function .m file. I would like to use eq. many times so I want to create a .m file that I call when calculating.
I get,
>> ns(-32.1,785e-9,1e-2)
n =
@(dBcalc,wave,zL)log(10^(dBcalc/10))/((4*pi*zL)/wave)
ans =
@(dBcalc,wave,zL)log(10^(dBcalc/10))/((4*pi*zL)/wave)
Lizan
Lizan 2012년 5월 30일
How do I make it so it execute the operation?
Lizan
Lizan 2012년 5월 30일
Never mind, solved it. Thanks...!

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

 채택된 답변

Oleg Komarov
Oleg Komarov 2012년 5월 30일

1 개 추천

In a script define:
ns = @(dBcalc,wave,zL) log(10^(dBcalc/10))/((4*pi*zL)/wave)
ns(14,765e-9,1e-2)
Note the 1e-2.
Alternatively:
function n = ns(dBcalc,wave, zL)
n = log(10^(dBcalc/10))/((4*pi*zL)/wave);
end

추가 답변 (0개)

카테고리

제품

질문:

2012년 5월 30일

Community Treasure Hunt

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

Start Hunting!

Translated by