When Matlab is processing code including the plot() command, Matlab will steal window focus, when plot() is processed. While many seem to find this behavior annoying, I find it useful as an alert telling me when the plot has been processed, and I can do something else while Matlab is running.
I would, however, like to have Matlab stealing window focus whenever calculations are done (Matlab being idle), and not just when I include the plot() or figure() command.
I have found a post about disabling the window stealing behavior of plot() and figure() (Inhibit Matlab Window Focus Stealing), but not on adding window stealing behavior when calculations are done. Can it be done?
To make Matlab command window get focus, you can add commandwindow after the calculations. From the documentation,
commandwindow opens the MATLABĀ® Command Window when it is closed, and selects the Command Window when it is open.
To make an existing figure get focus, you can add figure(h), where h is the figure handle. From the documentation,
figure(h) does one of the following [...]
If h is the handle or the Number property value of an existing figure, then figure(h) makes that existing figure the current figure, makes it visible, and moves it on top of all other figures on the screen. The current figure is the target for graphics output.
Related
I have made a Gui program that I compile to EXE application which lots csv file into graph data. I buit a save button but I do not know how save figure with different name each time cause (savefig anduisave both uses matlab program). I am posting my code below if anyoff you guys figure out how to save gui figue into image or anything that does require matlab to open. Last function is the callback function for save button.
function ma_Callback(hObject, eventdata, handles)
% i tried uisave but not possible to run computer without matlab cause mcr
% does not run uisave
% i tried copyopbj but since i did not put a name on my figure it did not
% work
%savefig
If you are trying to save a kind of image from your figure, then the best option which supports many aspects, is using print function.
I have already done this in a compiled app and it works perfect. Using print function you can set different file type(vector formats like *.svg are also supported), resolution(dpi), and so many others.
Although you can use print function directly on the figure, but I found that the best way (More Customization like removing or adding some objects and changing many options) is to follow this steps:
Create another figure with Visible='on' but a position that is out of screen with the same width and height of Main Figure.
normalized position = [-1, -1, ?, ?]. (Create this figure in start up and don't destroy it until your app exits, let call it Print Figure).
Copy your figure content (or the parts you are interested in) using copyobj to that figure (you may need to set Parent property of some key objects like panels to this new figure). They would look exactly as they look in the main figure, because they have the same properties. you can add or remove some objects in this step.
Change aspect ratio of "Print Figure" for a better output.
Print this figure with all options (file format, dpi, ...) you need. in my own GUI i allowed the user to change this settings with an input dialog.
In my app i used functions like winopen to show the output, and output directory to the user, when the print task was done. Print process takes some time, specially if dpi is huge, so it is also a good idea to inactivate buttons and show wait cursor.
Update:
a simple usage would be:
print(MainFigure, 'myFileName', '-dpng', '-r300')
I have a Simulink simulation containing a XY Graph block. When I start a simulation, it automatically opens an XY Graph, but I do not want this. I just want to be able to double-click on it after a Simulation if I wish to see its content, as I am also doing with scopes. I know that in a scope's settings, there is the option
Open at simulation start
I guess that there should be a similar setting to my XY Graph but I cannot find where it is. How can I prevent it from opening during a simulation?
Unfortunately, this block is implemented by an s-function that creates the figure (without providing much option there). So, the best that you could do would be to add code into a block (or model) callback to set the figure to not visible. Below is an example of how to find the figure handle and set it to not visible. This kind of thing can be found in sfunxy.m
Example:
set(get_param('your/xygraph/path','UserData'), 'Visible', 'off');
You would then need to run the following command to view the data (or create a shortcut).
set(get_param('your/xygraph/path','UserData'), 'Visible', 'on');
Obviously, this is not ideal. :)
Is there a command to maximize or manipulate in any way the size and placement of a plot window in Dymola?
After creating a plot using createPlot(), I would like to maximize that window within its allowed area of the screen.
No resource, either online or printed, has indicated how to do this, and none has said it couldn't be done. I am hoping someone can point me to a source that tells me how, or tells me to stop trying.
Here is the entirety of my test script:
simulateModel("TIL_AddOnTraining.Example07a", stopTime=300, method="dassl", tolerance=1e-005, resultFile="Example07a");
createPlot(
id=0,
position={0, 0, 857, 705},
x="valve.summary.dp",
y={"valve.summary.m_flow_A"},
grid=true,
colors={{255,0,0}},
thicknesses={0.7},
autoscale = true
);
[Here is where I would like the command to maximize window called "Plot [0*]".]
Thanks in advance.
Not an answer to the feasibility of doing this in Dymola, but here's a way to create and fine tune plot windows for Modelica using Mathematica and SystemModeler.
Needs["WSMLink`"]
sim=WSMSimulate["HelloWorld"];
plot=WSMPlot[sim,{"x","der(x)"},PlotLabel->"Very Interesting Plot\[Dash]Full Screen"];
CreateDocument[plot,WindowSize->Full]
The setting WindowSize can be changed to different options to select a fraction of the window, full screen, pixel size, and so on.
How to copy (to clipboard) only significant part of a plot in Matlab? Without that large gray margins Matlab loves so much?
Is it possible to populate clipboard from Matlab command line?
As far as programmatically populating the system clipboard with image data captured from a Matlab figure goes, you might try Yair Altman's, ScreenCatpture utility on the Matlab File Exchange:
screencapture('handle',gca,'target','clipboard');
It has a lot of options and will allow you to specify a region or an entire figure. It does require Java, i.e., it won't run in '-nojvm' mode. You can read more about it at Yair's Undocumented Matlab site.
Also, you can change the current figure's background color to white before copying it via:
set(gcf,'Color','w');
In the figure window, choose "edit" -> "Copy Figure".
It's equal to Ctrl+C on text, etc., but takes only the main part of the figure. So if you go to word, say, and press Ctrl+V, or RIght Click -> Paste, you will get only the main part of figure, without the gray margins you hate so much...
Stupid, simple question - is the value of gcf in matlab always going to be the figure number of the active figure? I.e., if I'm working on Figure 5, will gcf always return 5?
GCF returns the handle of the "current figure". This is always the figure number of the active figure. However, if you click on a different figure in the meantime, that other figure will become active. Thus, if you already know what figure you're working with, because you either forced the handle to 5 by calling figure(5), or because you captured the handle in a variable by calling fh=figure; it is safer that you use the handle instead of gcf whenever you want to modify the figure to avoid risking to inadvertently making another figure active.
Also, if there is no figure currently open, gcf will open a new figure.
This is a little more complicated than a simple "yes" or "no" answer. The handle for the current figure will generally match the number displayed at the top left of the figure window, but this number is only displayed when the 'NumberTitle' figure property is set to 'on' (the default).
Another wrinkle is that the figure handle is not guaranteed to be an integer. There is an 'IntegerHandle' figure property which determines if the handle created for the figure is an integer or a non-reusable real number. If this property is set to 'off', you get handle values that aren't integers, so the first figure that you open won't have a handle of 1. For example:
>> hFigure = figure('IntegerHandle','off') %# The only window open
hFigure =
173.0040
And the figure is numbered accordingly:
Notice that when the figure number and handle are displayed, there is some round-off of the number. The figure window only displays 6 digits past the decimal place. It becomes apparent that you're dealing with floating point numbers when you change the format of the Command Window to show more decimal places:
>> format long
>> hFigure
hFigure =
1.730040283203125e+002
In this case, the displayed figure number and the figure handle differ slightly.
Yes, gcf will return the handle of the currently selected (or active) figure. From the documentation,
H = GCF returns the handle of the current figure. The current
figure is the window into which graphics commands like PLOT,
TITLE, SURF, etc. will draw.
But also remember that:
The current figure is not necessarily the frontmost figure on
the screen.
One way to make a figure "current" is:
Clicking on uimenus and uicontrols contained within a figure,
or clicking on the drawing area of a figure cause that
figure to become current.
Another way is to use the figure handle. i.e., if you called the figure as h=figure;, then figure(h) will make it the current figure.