Effacer les filtres
Effacer les filtres

Use user input in a function

1 vue (au cours des 30 derniers jours)
Chesus
Chesus le 6 Sep 2023
I want to use a user input variable in a function
like:
n=input('n')
k=3
f1=func(k)
function f1=func(x);
f1=n*x;
end
But when I write that code it gives me this message:
Unrecognized function or variable 'n'.
Error in untitled>func (line 5)
f=n*x;
How can I do this?

Réponse acceptée

kei hin
kei hin le 6 Sep 2023
k=3
f1=func(k)
function f1=func(x);
n=input('n')
f1=n*x;
end
or
n=input('n')
k=3
f1=func(n,k)
function f1=func(n,x);
f1=n*x;
end

Plus de réponses (0)

Catégories

En savoir plus sur Startup and Shutdown dans Help Center et File Exchange

Produits


Version

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by