Anonymous function inside of function file
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Attatched is the problem and my attempt so far.
3 commentaires
Jan
le 12 Fév 2019
Whenever you mention in the forum that an error occurs, post a copy of the complete message. It is easier to fix an error than to guess, what the error is.
Please post the code as text, not as screenshot. The latter does not allow to fix your code by copy&paste, but requires a re-typing of what you have done already.
Réponses (1)
Jan
le 12 Fév 2019
Modifié(e) : Jan
le 12 Fév 2019
Your anonymous function CfromF takes one input and converts its contents. In your code you call this function without an input argument as "(CfromF)", but you need CfromF(T) with an input argument. Please read and post the error message, which clarifies this problem.
Your function obtains the input T from the outside. You initialize F as empty matrix and overwrite T afterwards. Then the input is lost. Better: avoid smart tricks with anonymous functions. Simple convert the value directly:
function rho = density(TF)
TC = (TF - 32) * 5/9;
...
If you want to learn how to do this more complicated:
function rho = density(TF)
CfromF = @(F) (F - 32) * 5/9;
TC = CfromF(TF);
...
In both cases use the value TC afterwards.
2 commentaires
Voir également
Catégories
En savoir plus sur Logical 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!