自动响应提示内循环

时间:2019-03-21 11:53:12

标签: matlab input

我有一个函数,要求每次运行都输入一个字母:

function [tp, yp] = backEuler(dydt,tspan,y0,h,varargin)
% dydt = system of equations/first order ODEs
% tspan = [ti  tf] start time and end time
% y0 = [ y(0) y'(0) ...] initial values
% h = step size
% varargin = various parameters for dydt
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

if nargin<4,error('at least 4 input arguments required'), end
if any(diff(tspan)<=0),error('tspan not ascending order'), end
n = length(tspan);
ti = tspan(1);
tf = tspan(n);
if n == 2
    t = (ti:h:tf)';
    n = length(t);
    if t(n)<tf
        t(n+1) = tf;
        n = n+1;
    end
else
    t = tspan;
end
tt = ti;
y(1,:) = y0;
np = 1;
tp(np) = tt;
yp(np,:) = y(1,:);
i=1;

bb = sym('bb',[1 length(y)]); % array of symbols to match with values in y
while(1)
    tend = t(np+1);
    hh = t(np+1) - t(np);
    if hh>h,hh = h;end
    while(1)
        if tt+hh>tend,hh = tend-tt;end
        %y(i+1,:) = solve( bb == y(i,:) + hh*dydt(tt,bb,varargin{:}));

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    % breaks here
    solve( bb(:) == y(i,:) + hh*dydt(tt,bb(:),varargin{:}));
    % I've tried using {:}, {:}(1), (:) for indexing on bb.
    % I've also looked at the workspace and every bb has the same 
    % basic dimensions as the output from dydt.
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %y(i+1,:) = y(i,:) + phi*hh;
       tt = tt+hh;
       i=i+1;
       if tt>=tend,break,end
   end
   np = np+1; tp(np) = tt; 
   yp(np,:) = y(i,:);
   if tt>=tf,break,end
end

我想做一个循环,在询问时将自动执行答案“ y”。可能吗?

编辑:该函数由程序调用,并且格式为我无法打开-.mexw64,.mexw32,.mexmaci64,.mexglx,.mexa64

0 个答案:

没有答案