Effacer les filtres
Effacer les filtres

User-defined Functions Applied throughout a Script

3 vues (au cours des 30 derniers jours)
Richard
Richard le 7 Août 2011
Hi,
I am attempting to write a Matlab script that uses a user-input (hence general) function, f(x), throughout the script. I thought of using he following:
f = @(x) input('Enter f(x): ')
but then when my (iterative) While loop is executed which contains (f(x)), the prompt pops up after every cycle.
I'd be grateful for any help!

Réponse acceptée

Walter Roberson
Walter Roberson le 7 Août 2011
If you have a sufficiently new version of MATLAB,
f = str2func(['@(x)' input('Enter f(x):','s')]);
If your version of MATLAB is a bit older, you need to either inline() or eval() instead of using str2func()

Plus de réponses (0)

Catégories

En savoir plus sur Function Handles dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by