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
Related
I'm trying to change font size of axes, legend and title of a scope used in simulink. I've seen lots of answers for changing font size in a plot made from workspace, like using 'setgca' and 'fontsize' property, but couldn't find anything about changing font size within a simulink scope.
I have tried couple methods, but there's no direct way to implement this. However, we could adjust the font size of titles and x/y labels inside the Figure associated with scope
Directing to scope to figure
After you run the scope, click the scope. In the task bar, select
File > Print to Figure
This will bring you to a figure where we can edit figure's fonts.
Edit font inside the figure
Edit > Figure Properties
In the pop-up window, edit the font.
In simulink is possible to change the font style and size using going to:
Diagram > Format > Font Styles for Model
There you can change the font style and size for blocks, lines and annotations.
There isn't any functionality to change these from a pulldown menu, however, they can all be changed using code.
The primary thing to note is that a Simulink Scope is just a MATLAB Figure Window in disguise, and hence it can be manipulated using standard Handle Graphics commands once you have the handle to the scope block you want to manipulate.
For instance to change the size of the legend you'd do:
% Get the Name of the block you want to change
scope_name = get_param(gcb,'Name');
% Get the handle of the figure window used for the scope
hs = findall(0,'Tag','SIMULINK_SIMSCOPE_FIGURE','Name',scope_name);
% Get the handle to the axes on the scope
% (For simplicity, here we'll assume there is only one axis on the scope.
% If there are multiple axes, then you'll need to select which one to manipulate.)
ha = findall(hs,'Type','Axes');
% Get the handle to the legend
hl = get(ha,'Legend');
% Change the font size
set(hl,'FontSize',12);
Given any of the above handles you can manipulate it using set and get just like any Handle Graphics object.
I am not sure how to access the scope object from MATLAB, however, I managed to change the legend and titles text sizes by simply resizing the scope window. I know it's not exactly the right way to do this but it works.
Here is a very simple MWE :
figure
x = 1:10;
plot(x)
title('mytitle','interpreter','none')
And the result with no title showing :
I am under Windows 7, Matlab R2015a. I do want the interpreter to be set to 'none' because I will be working with titles containing consecutive underscores - which would fail in Latex. And when I open the figure properties dialog and double-click on the title, it appears and is editable. Once I unselect it though, it disappears again. Help...
The problem here was that Matlab's default font was Helvetica, which is not available on my computer. So make sure to use a font available on your computer, by using the FontName argument if needed.
You can also set the default text font (here Courier) through :
set(0,'defaultTextFontName','Courier')
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!
I have tried most of the usually used options (print(figr, '-depsc', 'cross_corr.eps');) to save a matlab figure as eps/pdf but each time I do it, the figure contents are saved partially and perhaps one quarter of it is lost.
I have shared the figure here: http://ge.tt/2ZrsdD02/v/0?c
Using the options such as the following save it completely but I prefer it save it directly inti eps/pdf:
print(figr, '-dpng', 'cross_corr.png');
The problem seems to be that you have very small values in the 'PaperPosition' property of the figure. Try changing them to the default ones,
set(figr, 'PaperPosition', [0.634517 6.34517 20.3046 15.2284])
and then apply your print(figr, '-depsc', 'cross_corr.eps').
I attach results on my computer without and with 'PaperPosition' correction (using GSview with bounding box showed):
Also, consider reducing font size to avoid overlapped text:
set(findobj('type','text'), 'Fontsize', 5)
If I first enlarge the figure size (by using the middle button on the top right), and then save it as eps, I get this: http://ge.tt/1Pv8YE02/v/0
The quality is very nice as compared to all other options and the content are also ok.
Its not possible to automate it through script?...
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')