Answer input() automatically

243 Views Asked by At

Here's a potentially out-of-the box question: I would like to automatically 'answer' an input() command in Matlab. How could this be achieved?

Background: There's a static piece of code I need to work with, but would like to automate.

function test()
  nested_func();
    %nested function calls input
    function nested_func()
        name=input('Please tell us your name: ','s');
    end
end

I tried Java robots to enter things into console, however this should only run when the input function is in effect and therefore also pauses all commands, so nothing else can be entered:

import java.awt.*;
import java.awt.event.*;
rob=Robot;
disp('Henry'); %types 'Henry' as 'fake input'
rob.keyPress(KeyEvent.VK_ENTER); %presses enter key

EDIT: adapted example to include nested function calling input() as example for GUI calling it

0

There are 0 best solutions below