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

3 ビュー (過去 30 日間)
Alejandro
Alejandro 2014 年 10 月 16 日
回答済み: dpb 2014 年 10 月 16 日
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 give lock it in??

採用された回答

dpb
dpb 2014 年 10 月 16 日
Sure, get rid of the loop entirely...that's Matlab's forte--
...
nn=ceil(segeval/dt)
t=linspace(0,segeval,nn);
funcion=input('What function with respect to "t" do you wish to evaluate ')
func=funcion(t);

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by