Effacer les filtres
Effacer les filtres

vector-valued function element as function handle

1 vue (au cours des 30 derniers jours)
Federico Maglione
Federico Maglione le 24 Juil 2019
Modifié(e) : Matt J le 24 Juil 2019
Dear all,
I guess I have a relatively simple problem, but I could not find any solution online. The built-in Matlab function
[AssetPrice,OptionValue] = binprice(Price,Strike,Rate,Time,Increment,Volatility,Flag)
generates the two outputs AssetPrice and OptionValue. The first is a matrix the second a scalar. I need the scalar only and I would like to make it as a function of one specific variable, i.e.
[~,OptionValue] = @(Volatility) binprice(Price,Strike,Rate,Time,Increment,Volatility,Flag)
being all the other inputs known. However, defined in this way I get the error "The expression cannot be assigned to multiple values". If the function binprice would return only one output (instead of two), the previous syntax would work.
How do you overcome this problem?
Thank you,
F

Réponse acceptée

Matt J
Matt J le 24 Juil 2019
Modifié(e) : Matt J le 24 Juil 2019
With a wrapper,
fun=@(Volatility) mybinprice(Price,Strike,Rate,Time,Increment,Volatility,Flag);
function OptionValue = mybinprice(varargin)
[~,OptionValue] = binprice(varargin{:});
end
  4 commentaires
Matt J
Matt J le 24 Juil 2019
Modifié(e) : Matt J le 24 Juil 2019
I don't have the Financial Toolbox, so cannot test it. What happens if you put a break point at
[~, OptionValue] = binprice(varargin{:});
What is returned in OptionValue? Also, the documentation says that OptionValue is vector-valued, so why exactly are you expecting a scalar?
Federico Maglione
Federico Maglione le 24 Juil 2019
Thank you. It works perfectly.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Graphics Object Programming dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by