X11 MATLAB Display Figure - matlab

I know it's possible to forward any output from a remote machine to a local one by using the X11 forwarding remote tunnelling, so that when you run a MATLAB command it will display all the graphical outputs back to the machine you've connected from.
My question is:
Is there any MATLAB command to just output the figures (e.g., plot,surf,etc.) without displaying any other graphical object (i.e., the main interface)?
In practice, I would like to interact with MATLAB by using the command line (as shown below) and forward back only the figures.

MATLAB cannot display figures without its own figure-GUI, so the answer to your question would be no.
However: there is a workaround: create an invisible figure using f=figure('visible', 'off'), then plot your data, and finally use saveas(f,filename,fileextention). Don't forget to close(f) your figure after saving, to free the RAM. You'll now have a figure in your file directory, which you can display using your favourite visualising tool, which might even be possible through a call to system, although I have never tested that.

Related

Matlab - Transforming my program into a GUI [duplicate]

This question already has answers here:
How can I program a GUI in MATLAB? [closed]
(4 answers)
Closed 6 years ago.
I wrote a code that: imports sequential files containing x- and y- columns, plots the data, fits the peaks using a 4-term gaussian, saves the plots as .png image files and finally exports all the variables into a table (called final). I want this program to be user friendly as non-programmers need to use it. Please let me know if it is possible. I would like to be directed towards the right path. As I do not know where to start.
There are thousands of resources on-line, but they are not specific. I would like to know if it is possible in my case to create a GUI, so I dont fish in an empty pond.
You might consider using "GUIDE" which is Matlab's GUI design environment. It's fairly easy to use. To start simply type:
guide
in the command window. There is a lot of documentation on how to make a gui with guide. I'd wager you could quickly come up with a gui that calls your script, or you could convert your script to a set of functions and call those from the gui.
http://www.mathworks.com/help/matlab/creating_guis/about-the-simple-guide-gui-example.html

Why is my deployed MATLAB application unable to generate a new figure?

I have built a GUI with some text boxes and a pushbutton. When I execute the GUI from MATLAB, it produces the desired plot on a separate window. The plot is created by a function that is stored in the same directory and is called in the callback function of pushbutton.
When I package it with the .m file of the GUI as the main file, I get an exe. When this exe runs, it normally takes data from data source (sqlserver) but then does not give the plot in a separate window as within matlab (also not in the same GUI window). There is a sound and from the behaviour it seems that the plots appears and vanishes in a very short time. But this is my perception and may be wrong, maybe it is some error message that is suppressed.
What can I do to solve this?
You've run into the problem discussed here in this post
Once the code is finished evaluating it cleans up, including closing the window you created. One solution would be to pause your script right after plotting.
Here's a discussion of many functions that can be used to pause execution with a GUI.

Disable plots in Matlab

I have some programs written in Matlab that I need to run several times for some reasons (debugging, testing with different input, etc...)
But, there are a lot's of graphs that are plotted by the programs and its various functions such that everytime I run the program, I have to wait for all the graphs to be displayed, which is very annoying and time consuming (especially when you are working with a small laptop).
After the program is executed, I close them with a close all.
So my question is:
Is there a way to disable all plots/figures/graphs in Matlab? either in the options, or by executing a certain code like disable plot and enable plot to ensure that no figures are being displayed.
I know that I can just browse the code and comment the plotting part, but I don't want to forget to uncomment.
Try some combination of the two commands:
set(gcf,'Visible','off') % turns current figure "off"
set(0,'DefaultFigureVisible','off'); % all subsequent figures "off"
The second one, if you put it near the beginning of your program, might do the trick for you. Of course, it is still creating the plots, which might be undesirable for computation time and/or RAM issues.
This is a classic reason to avoid Matlab when one can. It fosters bad programming design. To solve this problem correctly, you should create something that lets you "flip a switch" at the highest level of your program and control whether plots show or do not show. Perhaps it even has gradations of the show/don't show option so you can select different types of plots that do/do not show depending on what diagnostics you are running.
Ideally, you'd want this "flip a switch" creation to be a class that has access to visibility and plot functions of other objects. But because interactive object-orientation is so cumbersome in Matlab, it's often not worth the effort to develop such a solution, and most people don't think about this design aspect from the outset of their project.
Matlab would encourage someone to solve this by making flag variables like "isPlotVisible" or something, and creating functions that always accept such flags. I agree this is a bad design.
You could run matlab from the command line with:
matlab -nojvm
but then you don't get the GUI at all. Alternatively, you could write a file 'plot.m':
function h = plot(varargin)
h = [];
end
which doesn't do anything. If this is in the working directory (or somewhere else near the top of the path), then plot will call your function instead of the 'real' plot. You'd need to do the same from any other graphing functions you call.
The closest way I know of 'turning off plotting' would be a folder of such functions that you can add to the path to disable plotting, and remove to enable.
The previous methods are fine, but an easy and good habit to take is to use a "on/off parameter". So basically, at the beginning of your code, you can add something like:
DisplayFigure = 1; %1 = display, 0 = no display
After that, add "if DisplayFigure == 1 ... end" for all your plotting related commands, where the commands should be inside the if statement (the ... above). Hence you won't even compute the plots, which will save you a lot of time and memory. You just have to change the value of the variable "DisplayFigure" to plot or not the figures.

matlab cell mode with vim/gvim

I want to run a cell using vim. however, using what I see here:
How to implement MATLAB-like cell mode in Vim
I get a matlab instance starting, running and then closing. Is it possible to to this like it would be on a real matlab? ie I have a vim on one side and matlab on the other (open all the time), and by a vim command I get the cell to run on the matlab?
Not sure whether this is exactly what you want, but you might want to browse through these answers

How can I get a list of all the defined variables in Matlab or Octave?

I'm used to working in Matlab using its full GUI environment. Due to license issues I went and installed Octave, but it appears that it doesn't have a GUI, at least not one that's installed by default.
I transferred the variables from Matlab to Octave by saveing them in Matlab and loading them in Octave. Thing is, I don't remember the names because I got used to seeing them in the little workspace window which I no longer have.
How can I see the list of defined variables and their types in Octave?
The command whos will do just that.
With the command whos you can even see the variables that the file has WITHOUT opening the file, to be assure that this file is the one.
For example, the name of the file is MyVariables.mat
use:
whos('-file','MyVariables.mat')
You can use a GUI similar to Matlab, such as QtOctave or GUIOctave.