The short answer is no. This can't be done as you want it to. What you are trying to do is to write text to MATLAB's stdin
and let it remain there unprocessed. Essentially a modified form of piping.
The closest option available in MATLAB is Evaluate Selection where when you select text you can cause MATLAB to execute it in the command prompt. MATLAB puts this text exactly where you want it but it also immediately executes it. There does not seem to be a way to halt this or emulate its functionality programmatically.
Writing to stdin
in MATLAB is not allowed as you can see from
>> fprintf(0, 'help conv')
Error using fprintf
Operation is not implemented for requested file identifier.
where 0
denotes stdin
, 1
denotes stdout
and 2
denotes stderr
. Another naive attempt would be to use fopen()
>> fid = fopen(0, 'w');
Error using fopen
Invalid filename.
but alas this fails too. However, we can see from the first attempt that what you desire
is not implemented
The only option to get exactly what you want is that possibly with some MATLAB hackery the ability is there but I'm not aware of it or anybody who has even attempted it.
EDIT: Luis Mendo has provided the MATLAB hackery solution I was talking about.
The closest you could get to what you want is to use hyperlinks to run MATLAB commands like
>> disp('Did you mean: <a href="matlab:conv(a,b)">conv()</a>')
Did you mean: conv()
ans =
12
where conv()
is a hyperlink and clicking on it will execute conv(a,b)
where a = 3;
and b = 4;
in this example.