Matlab: how to stop command window printing? [duplicate] - matlab

This question already has an answer here:
How to abort a running program in MATLAB?
(1 answer)
Closed 7 years ago.
Sometimes I accidentally print a say 5000x5000 matrix, which takes a long time. How can I stop the command window from printing?
I am using Matlab R2015a on a Mac. Thank you very much.

On a Windows machine, it's Ctrl + C. This stops executing code as well as printing. I assume it is comparable on a Mac: Ctrl + C.

On a mac it's
CTRL+C
Sorry for the short and not very appealing answer.

clc to clear the command window, ctrl+c to stop execution and ; at the end of the line you don't want to print will suppress the command window output.

Related

How to close MATLAB editor window/windows using command? [duplicate]

This question already has answers here:
How to close one or all currently open Matlab (*.m) files from Matlab command prompt?
(2 answers)
Closed 4 years ago.
I want to know if there is any way to close the editor window (like function, script)using Matlab command.
Step 1. Get the editor service
editor = com.mathworks.mlservices.MLEditorServices; % main editor service
Step 2. Choose either of following depending on your requirement
editor.getEditorApplication.close; % Close editor windows (with prompt to save)
editor.getEditorApplication.closeNoPrompt; % Close editor windows

Showing the figure window with octave

I am a very newbie to octave.
I want to show the figure I plot with octave, but no figure window shows up.
Here is what I want to plot, plot.m
x = load('ex2x.dat');
y = load('ex2y.dat');
figure % open a new figure window
plot(x, y, 'o');
ylabel('Height in meters')
xlabel('Age in years')
I run the script with the command line directly
octave plot.m
The dataset can be downloaded from http://openclassroom.stanford.edu/MainFolder/DocumentPage.php?course=DeepLearning&doc=exercises/ex2/ex2.html
I have installed image package as the site suggested.
My OS is ubuntu 14.04, I am not sure if I miss something.
I appreciate any help.
Thank you!
I found the answer which can be found in Octave's FAQ.
http://wiki.octave.org/FAQ
If you are running an Octave script that includes a plotting command,
the script and Octave may terminate immediately. So the plot window
does show up, but immediately closes when Octave finishes execution.
Alternatively, if using fltk, the plot window needs a readline loop to
show up (the time when Octave is sitting around doing nothing waiting for interactive input).
A common solution is to put a pause command at the end of your script.
So I just to add pause in the end of my script and it shows the window.

MATLAB Opening Examples and findpeaks()

I have two issues. First I can't figure out how to properly enter commands openExample('matlab_featured/intro')
http://www.mathworks.com/help/matlab/examples/basic-matrix-operations.html
However, if I go top Help->Example and open up examples from there it works fine.
My second issue is that findpeaks() doesn't seem to work. For instance, the code below causes and error at the findpeaks() command.
data = [25 8 15 5 6 10 10 3 1 20 7]
plot(data)
pks = findpeaks(data)
I'd try opening the example, but I can't find it in the documentation via MATLAB, but I can find it if I go to their site.
The example can be opened just by entering 'intro' in the command
line.
There is a documentation about findpeaks. Just type 'findpeaks' in
the command window and press 'F1' on your keyboard immediately.

Prepare command in MATLAB

Is there a way in MATLAB to prepare a command programmatically (ie. writing a command directly to the command prompt) so the user can execute it by pressing an enter?
I want to implement my own "Did you mean:" functionality, that is built into MATLAB already.
It can be done using Java from Matlab to programmatically generate key events, along the lines of this answer.
Let's say the command you want to "prepare" is dir. Then
commandwindow; %// make Matlab command window have focus
robot = java.awt.Robot; %/ Java Robot class
robot.keyPress (java.awt.event.KeyEvent.VK_D); %// key press event
robot.keyRelease (java.awt.event.KeyEvent.VK_D); %// key release event
robot.keyPress (java.awt.event.KeyEvent.VK_I);
robot.keyRelease (java.awt.event.KeyEvent.VK_I);
robot.keyPress (java.awt.event.KeyEvent.VK_R);
robot.keyRelease (java.awt.event.KeyEvent.VK_R);
will type dir onto the command window, exactly as if the user had written it. Then pressing Enter will run the command.
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: conv()')
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.

How to make output of Matlab m file to stay for a while

I have matlab m file which plots 3 graphs using subplot. Now i also have a UNIX script which invokes this script and passes the function name as parameter.
I have two problems:
I am getting the warning Type-ahead buffer Overflow
The plot remains only for a few seconds before disappearing. How can I keep plot active til l user clicks on cross button?
thanks!
It's hard to answer your first question without some code.
You can use the pause command to wait for the user to press any key.