I'm using an external monitor. My notebook has display of height 800 px, but monitor has over 1000 px. If I'm running the script on external monitor
screenSize = get(0,'MonitorPositions');
figureSize = screenSize(4);
figure('Position',[0 0 figureSize figureSize])
the size of the new figure won't go over the size of notebook display. Is there a way how to fix this?
EDIT
I have found that if I start MATLAB while having already set the external monitor as an output device, the script runs just ok. Is there any way how to reset settings, that are responsible, before running the skript?
You probably want:
figureSize = screenSize(monitorNumber,4);
As screenSize(4) will give you the 4th element in the matrix - same as screenSize = screenSize(:)
By default figures are displayed on the primary display. If you want to force Matlab to show figures on the external monitor, you need to set the DefaultFigurePosition to a value that is actually on the secondary monitor.
Therefore, let's say you create a figure and drag it on the external monitor. Then you can fetch the current position and set it to the default like so:
FigPos = get(gcf,'Position');
set(0, 'DefaultFigurePosition', FigPos);
Then figures will subsequently appear on the external monitor with a size that fits. That's not perfect since you need to create a figure, drag it and then delete it and it's only valid for your current session. However you can add the previous lines of code in your startup.m file to do it automatically.
Hope that helps somehow!
Related
I have a 3 monitor Gentoo Linux system running MATLAB. MATLAB runs on the center monitor. I need MATLAB to generate plots on the left monitor but it always plots on the right monitor.
I believe this is at least partially caused by the non-standard way I have my monitors arranged physically - essentially 2,3,1:
>> get(0,'MonitorPositions')
ans =
1 1 1920 1080
-3839 1 1920 1080
-1919 1 1920 1080
Is there a way I can control this as a default within MATLAB?
You can set the default figure position on the root object like so:
set(0, 'DefaultFigurePosition', [-3839 1 1920 1080]);
This will create windows that fill the left monitor by default. However, this default will likely reset each time you restart MATLAB, so you will have to put it in your startup file if you want it to persist from session to session.
Note: The documentation for the 'MonitorPositions' property of the root object says this:
The first two elements in each row indicate the display location with respect to the origin point. The last two elements in each row indicate the display size. The origin point is the lower-left corner of the primary display.
If you change which monitor is used as the primary display, the relative coordinates in the left two columns will change, meaning you will have to change the position value in the above line of code. If you think the display setup may change often, or you will be running code on different monitor setups, then you can ensure plots will always appear on the left-most monitor by looking for the monitor position with the lowest value in the left column. Here's how you could do it (also incorporating the previous default window size and position within a monitor):
monitorPos = get(0, 'MonitorPositions');
figurePos = get(0, 'DefaultFigurePosition');
[~, leftIndex] = min(monitorPos(:, 1));
set(0, 'DefaultFigurePosition', figurePos + [monitorPos(leftIndex, 1:2)-1 0 0]);
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.
I used Matlab GUIDE to create a GUI.
It is displayed mid-screen.
How can I position it at the top of the screen; so that the top edge of the GUI window is at top of screen.
It will be used on different Windows 7 computers with different screen resolutions.
I tried to set hObject.Position(2) but it doesn't do what I want.
I think the simplest way would be to use movegui in the OpeningFcn of your GUI with the appropriate argument, i.e. using either 'north', 'northeast' or 'northwest'.
The calling syntax is quite simple, using the handles to the figure created. In GUIDE, the default name for figures is "figure1", so in your case the code would look like this (unless you changed the figure's name):
movegui(handles.figure1,'northwest') %// or whatever
Note that movegui calls the following 3 functions to get the screen size and monitor positions/units:
screensize = get(0, 'ScreenSize');
monitors = get(0,'MonitorPositions');
old0units = get(0, 'Units');
So you could do the same to make the calculations yourself in order to place the figure precisely where you want if the above solution is not sufficient for you.
I would like to temporarily change the font size of the text in the command window of MATLAB. I am running an experiment in which I am standing at the other side of the lab, and need to occasionally read a number from the screen. I don't want all the MATLAB output to be jumbo size forever - just this one variable when it occasionally comes up. I expect there must be some code that increases font size? I know I can adjust for example font colour using the following code:
com.mathworks.services.Prefs.setColorPref('ColorsText',java.awt.Color.red);
com.mathworks.services.ColorPrefs.notifyColorListeners('ColorsText');
(The above changes the text in the command window to red). There must be similar code to set font size?
The ideal solution would be a parameter to add to the fprintf command, such that only the one bit of output is larger. However, I would accept a solution in which the entire output of the screen is made larger temporarily...
Any help appreciated.
What about displaying all output in a figure instead of the command line? You could place text-objects and define colors and font sizes.
One way is the following:
"File > Preferences > Fonts > Custom" and there set your font and size. But it's not accessible setting from the commandline itsel so you would have to set it manually and afterwards disable it.
Edit:
To pop out a figure and print out a certain variable is easy:
foo = 100;
figure
uid = uicontrol('Style', 'text','String', ['FOO = ' num2str(foo)], 'FontSize', 80, 'ForegroundColor', 'b', 'Units','normalized','Position', [0 0 1 1]);
you could also specify the position and size of the figure window itself, if you want to.
To close the figure later, just use:
delete(gcf);
If you want to update the value of it, just use something like
set(uid, 'String', 'New text')
HOME TAB -> ENVIRONMENT TAB -> Preferences -> Fonts
I have a generally happily running program that takes files, plots them, spits out a pdf (letter size). I use annotations to put in a title above a set of three subplots, and to use as a footer with file info and date. I would like the title to be at the top of the page, filling up from margin to margin, centered.
I have two ways of running the program: in 'batch' mode and 'interactive' mode. When in 'interactive' mode, I create the figure with a simple figure() command. When in 'batch' mode, I create the figure with figure('visible','off'). Here is my command for making the annotation:
annotation(obj.hFigure(f),'textbox',[0 0.9 1 0.1],...
'String',title,...
'HorizontalAlignment','center',...
'FontSize',18,...
'LineStyle','none',...
'FitBoxToText','off');
Here, "obj.hFigure(f)" is simply a handle to the figure I am currently processing. As you can see, I place the figure near the top of the figure, and make sure that the text runs off the bottom of the box (in case it is larger).
My problem is with margins on the above annotation. In batch mode (no figures showing), I get 10% or so margins on either side of the text, which ruins the layout. In interactive mode (figures show up), I don't get the margins: the text correctly flows from one edge to the other.
I have narrowed down the problem to the following: I can get the correct response to the ps printing in batch mode if I make the figures visible (figure('visible','on')) AND open up
propertyeditor(gcf);
plotbrowser(gcf);
after each figure is plotted. This makes the program take about twice as long (which isn't a huge deal). But what I don't understand is: what do those two commands do that drawnow or refresh don't accomplish?!
I am unsure about your specific case, but when encountering this kind of problem in the past I have had great success by explicitly setting the figure size with:
set(gcf, 'Position', [100 100 300 300])
and then, before printing/saving setting the PaperPositionMode to auto, which seems to force the printed figure to be the same size as the one shown on screen:
set(gcf, 'PaperPositionMode','auto')