Is it possible to lock or fix an input value given by the user, inside a for loop?

2 次查看(过去 30 天)
dt=input('time differential = ')
segeval=input('seconds to evaluate = ')
nn=ceil(segeval/dt)
func(nn,1)=zeros
t(nn,1)=zeros
cont=0
for i=1:nn
t=cont
funcion=input('What function with respect to "t" do you wish to evaluate ')
func(i,1)=funcion
cont=cont+dt
end
% this is the function in this case 10*sin((pi*t)/0.6)
This code works in evaluating the function at each different value of "t" but the problem is that, since it is in the for loop it asks the user every cycle for the function again. Any idea on how to lock it in??

采纳的回答

Star Strider
Star Strider 2014-10-16
Ask for the function first, before you enter the loop.
  5 个评论
Alejandro
Alejandro 2014-10-16
dt=input('diferencial de tiempo = ')
segeval=input('segundos a evaluar = ')
nn=ceil(segeval/dt)
func(nn,1)=zeros
t(nn,1)=zeros
cont=0
for i=1:nn+1
t(i,1)=cont
cont=cont+dt
end
funcion=input('introducir funcion de carga con respecto a "t" ')
% 10*sin((pi*t)/0.6)
That seemed to work, thank you anyway!

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Programming 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by