I am trying to run a function in octave from the command line. The function is currently run like so:
octave --silent --persist --eval 'function(input arguments)'
function.m contains a plot command. When I invoke octave with the above command line parameters, the plot does show but octave enters into its interactive mode. My question is:
Is there any way to get octave to display the plot without entering the interactive mode when it is invoked from the command line?
Just use pause after your plotting functions
You can use:
waitfor(h)
at the end, which waits for you to close the figure.
AFAIK, the plot window is a child process of octave and therefor can only be displayed when octave is running. Even if you plot something from the "interactive" mode leave the plot open and close octave, the plot will also disappear.
What you could do is to plot to some output file like posted here:
f = figure
set(f, "visible", "off")
plot([1,2,3,4])
print("MyPNG.png", "-dpng")
You need to select a proper graphics toolkit:
available_graphics_toolkits
ans =
{
[1,1] = fltk
[1,2] = gnuplot
}
The default is fltk which cannot write to file without displaying the plot. However, if you select gnuplot it will be able to write to file without displaying it first. In your file start with:
graphics_toolkit gnuplot
The problem is that when you run from command line, when it ends, the plot windows disappear with it.
#! /usr/bin/octave -qf
f = figure;
set(f, "visible", "off")
t=0:0.001:5*pi;
plot(t, sin(5*t)), grid
print("MyPNG.png", "-dpng")
This saves output to MyPNG.png in the directory where it is run.
Then you might open it with a visualization program.
Another option is to add
pause
at the end of the program so it waits for user input to terminate, therefore to close the plot window.
Cheers :)
Also can try wait for key.
while (waitforbuttonpress ()==0)
pause(1)
end
When I click on a function block in Simulink, it's Matlab code is opened in Matlab editor. I don't like it. I'd rather use Vim.
I tried changing editor in Matlab Preferences (Home->Environment->Preferences-> Editor/Debuger). I switched editor from "MATLAB Editor" to C:\Program Files(x86)\Vim\vim80\vim.exe.
But that makes vim open only when I type "edit" command in command line.
Using Matlab R2014b under Windows 7.
How do I display the current value of a variable in the matlab command window? In matlab I usually use disp(var) and it will output the variable value into the command window. However in the MATLAB function block if I were to enter disp('hello') it doesn't show any output in the command window. I am using matlab 2014b.
You idea for displaying output value in the command window is not a good approach to solve your issue. I would suggest you look at scope block if you'd like to see the value during simulation. Or use To Wrokspace block if you'd like to output the value into main workspace.
For debugging your code and design, read and use Simulink Debugger should be helpful.
1 I run matlab without GUI, sometimes I would like to see commandhisoty by using commandhistory function, but I found that if I run matlab without GUI, the program cannot save any command history like the GUI matlab, are there some methods to solve this problem?
2 I tyied to use diary, but it seems that it can only save all commands and outputs. In addition, it seems that I should type diary every time when I open matlab, the default option is diary off. How to make it more convenient to use
I use matlab without GUI, I wonder how I can run part of the matlab codes in terminal.
I can run part of the codes in the default matlab editor.
reference:
matlab-emacs
http://www.mathworks.com/help/matlab/matlab_prog/run-sections-of-programs.html