Use user input in a function

1 次查看(过去 30 天)
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?

采纳的回答

kei hin
kei hin 2023-9-6
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

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Startup and Shutdown 的更多信息

标签

产品


版本

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by