vi input mode in command line Matlab?
Yes, that should be easy enough. It's just a special case of the general "open a process and bind to its stdin and stdout" problem, and that's not difficult.
A bit of Google searching finds that IO.popen()
is the right piece of Ruby for that, and there's a little more detail in the replies here: http://groups.google.com/group/ruby-talk-google/browse_thread/thread/0bbf0a3f1668184c. Hopefully, that's enough to get you started!
Update: Looks like you're almost there with your wrapper. What you need to get finished is recognize when Matlab is asking for input, and only ask the user for input then. I'd suggest trying this pseudocode:
while input_line = Readline.readline('>> ', true)
io.puts input_line
while ((output_line = io.gets) != '>> ') // Loop until we get a prompt.
puts io.gets
end
end
That's not quite right, as you need to do the inner loop once before you ask for the first input line, but it should give you the idea. You might need to adjust the prompt text that it's looking for, too.
Update 2: Okay, so we also need to account for the fact that there's no EOL after a prompt and so io.gets will hang. Here's a revised version that uses the fact that you can give a blank line to a Matlab prompt and it will just give you another prompt without doing anything. I've rearranged the loop to make things a little clearer, though this means you now have to add logic to figure out when you're done.
while [not done] // figure this out somehow
io.puts blank_line // This will answer the first
// prompt we get.
while ((output_line = io.gets) != '>> ') // Loop until we get a prompt.
puts io.gets // This won't hang, since the
end // prompt will get the blank
// line we just sent.
input_line = Readline.readline('>> ', true) // Get something, feed it
io.puts input_line // to the next prompt.
output_line = io.gets // This will eat the prompt that corresponds to
// the line we just fed in.
end
vi input mode in R?
The Vim-R-plugin should do the trick. I have used it in Ubuntu, MacOS, and Windows 7. The developer is great and does frequent bugfixes.
To get Vim behavior in the R console you'll need to use the Conque Shell plugin, which Vim-R-plugin supports. I tried it for a day but found modality in the R command line a little tedious. All I ever use is tab completion and last command.
Is it possible to write a MATLAB script that can give command line input to a function?
If you are looking for a non elegant solution.
If you are looking for a potentially dangerous solution.
Then you might try this: write a function named "input" as follows:
function a=input(str)
% THIS IS THE DUMMY VERSION OF THE
% MATLAB BUILT-IN FUNCTION "input"
global dummy_input
disp('WARNING!!!')
disp('MATLAB "input" built-in function overridded')
disp(['Setting dummy_inpt'])
a=dummy_input;
end
Declare a global
variable either in the script you use to test the function and in your "dummy" input
function.
Assign the desired value to the global variable
as follows:
global dummy_input
x=3;
dummy_input=123;
y=my_func(x)
dummy_input=42.13;
y=my_func(x)
If my_func
is the function you post in the question, you will obtain:
WARNING!!!
MATLAB "input" built-in function overridded
Setting dummy_inpt
y =
126
WARNING!!!
MATLAB "input" built-in function overridded
Setting dummy_inpt
y =
45.1300
I've added the printing of the warnings in the "dummy" input function yust as a remainder ...
You do not need to modify the function you want to test, when it will call input
to get a number from the user, it will call your "dummy" input.
Version 2 of the "dummy" input function
This version of the "dummy" input function allows autonatically handling multiple request of input values.
It requires the user knows in advance how many times the "original" input
function is called.
No additional global counter
is required.
It is sufficient the change the definition of the global parameter
in the script, declaring it as an array containing the set of input the user want to assign:
global input_list
input_list=[27 30 5 31 21]
In the "dummy" input
function, the first element of the array is assigned to the output variable, then the it is deleted:
a=input_list(1);
input_list(1)=[];
the code of the updated version of the function is the following:
function a=input(str)
% THIS IS THE DUMMY VERSION OF THE
% MATLAB BUILT-IN FUNCTION "input"
global input_list
disp('WARNING!!!')
disp('MATLAB "input" built-in function overridded')
disp(' ')
disp(' ')
disp(' ')
if(isempty(input_list))
error('Error in DUMMY input: no more input data')
else
disp(['Setting dummy_input ' num2str(input_list(1))])
a=input_list(1);
disp(' ')
disp(' ')
disp(' ')
input_list(1)=[];
end
end
An error
is generated in case the input array becomes empty
(by deleting its element at each call) before the end of the script.
I've also added some calls to disp
to make more "clear" the output on the Command Window.
Also the "dummy" input
function print a message on the Command Window telling which input values has been assigned.
Make sure to remove your dummy "input" function at the end
Hope this helps.
call system command within MATLAB
Use the echo
command to include a return message:
[status,message] = system('yourCommand && echo hello world' )
will return:
message =
hello world
Generally you will need to create a string where you cascade all your commands connected with &&
. One of the commands could then be echo something
.
Regarding your edit:
output = 'processing value ...'
command = ['cd ' myCMD ' && myCommand.bat' ' && echo ' output];
[status,message] = system( command )
will call myCommand.bat
and return "processing value...".
MatLab, missing - in command line
That's because you're starting a loop. It's waiting for you to type the code to go within the loop, and it is terminated when you type end
to end the loop. For example:
if(x==0)
y = y + 1;
end
Related Topics
Understanding Ruby Symbol as Method Call
How to Run Ruby 2.0 with Jruby 1.7
How Would I Go About Programmatically Interacting with VSt(I) Plugins to Synthesize Audio
Ruby: Creating a Hash Key and Value from a Variable in Ruby
Clarification on the Ruby << Operator
What's the Fastest Way to Check If a Word from One String Is in Another String
Rspec Testing Redirect to Url with Get Params
What Is the Activemodel Method Attribute "_Was" Used For
Model Using Modules in Rails Application
Don't Have Jekyll-Paginate or One of Its Dependencies Installed
Why Doesn't This Work If in Ruby Everything Is an Object
How to Authorize a Google Service Account Without the Default Credentials File
How to Split String into Only Two Parts with a Given Character in Ruby