Turquoise Blue Font in Matlab - matlab

I would like to know what the light blue/turquoise blue font in Matlab means. I am currently working on Bayesian Optimisation in Matlab and whilst going to some previous students' code, I came across a weird blue font colour I have never seen before in their function definition. I have checked my colour scheme settings in Matlab and this turquoise blue does not appear in the list of set colours. See the attached picture for reference.

By default this color means that the corresponding variable has shared scope. This can be because it is
a global variable (its scope is shared with the command window);
a persistent variable (its scope is shared across subsequent calls to this function); or
a variable that is used in a nested function (its scope is shared between the nested and parent functions).
Thus, this color indicates in general that the value of that variable can be affected from outside the function.
The color can be changed in the Matlab preferences window. The window also shows some example code that illustrates this:

Related

Plots all red and green

I seem to have made some settings change where all of my MATLAB plots (plot, plot3, surf, etc) show up in this red/green color scale:
I searched around forums and the MATLAB user guide but am not finding anything. It's not a huge deal, as I can enter code to fix this on each plot, but I shouldn't have to.
How to fix this?
Check startup.m you seem to have set your default colormap to autumn or something. Just put it back to either jet (pre 2015a), or parula.
I don't know about the whole settings. These two commands can reset a figure properties (including its colormap) to its default values:
h=gcf;
reset(h)
This way you assign a handle to the last figure you have. Then, the second command resets its options to default values.
Update after Adrian's comment: Check out this page: Default Property Values It clearly shows how is it possible to regenrate the problem you have and you might need use the remove option for removing user-defined default value. There is a factory defined colormap accessible by the function: get(groot,'factoryFigureColormap'). This might help you too.

How to change Font Size in Simulink Scope?

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.

MATLAB R2014b switch back to old color scheme?

As announced, MATLAB R2014b adopts a new color scheme, which sort of replaces red with orange and blue to gray blue.
I would like to opt back for the old scheme. How may I do this?
P.S.:
If I am simply plotting dot, lines, and all that, I can just specify the color myself. However, this is not the case.
I am calling a sophisticated drawing function, which displays the heat map with the MATLAB color scheme. They used to be "blue for cold, and red for hot", and now they become "gray blue for cold, and yellow for hot". It is just counter-intuitive!
Therefore, to avoid modifying the function, I would rather switch the whole graphics system back to pre-R2014b scheme.
The old default colormap is still available - it's called jet.
If you want to set the colormap for individual axes or figures back to the old default, you can do that with colormap(figHandle, jet) or colormap(axesHandle, jet).
To change it for all your plots, try set(groot, 'DefaultFigureColormap', jet). You may need to set that each time you start MATLAB, so perhaps you might want to put the command into a startup.m file.
However I'm not sure I agree that the new colormap is less intuitive; in fact there is quite a bit of solid evidence that it is much worse in some very specific ways. That's why they changed it. Your choice though...

IDE or plugin to add helpful graphics or illustrate code as-is?

I was staring at my code thinking how boring the text looks.
All I see is text, with no visualizable structure.
Visualizable structures would be awesome:
Background graphics such as 3D half-pipes on edge connecting the opening and closing brackets of loop scopes, nested in 3D to show how deep the loops are nested.
Wires with arrows along them showing where a goto statement points, with a code section highlight (or preview if out of viewport) of the target label.
Conditional blocks could be rendered to show the "true" code in a positive color and the "false" code in a negative color, and mousing over the background at the left edge could reveal a preview of the condition statement for that block (appended with "== true" or "== false" depending on the code context).
Icons for Types, that show up in front of variable names so you know what type they are.
Change the background of the method, displaying tiled locks or keys, depending on whether you type public or private in front of the method (a nice indicator of the default if you fail to specify either).
Is there anything out there that illustrates code like this?
I don't mean analytically generated graphics representing the code or algorthmic structure in some way. Rather, I mean something that actually illustrates the editable code in place.

How do I use TeX/LaTeX formatting for custom data tips in MATLAB?

I'm trying to annotate a polar plot with data tips labelled with 'R:...,Theta:...' where theta is actually the Greek symbol, rather than the word spelled out. I'm familiar with string formatting using '\theta' resulting in the symbol, but it doesn't work in this case. Is there a way to apply the LaTeX interpreter to data tips? Here's what I have so far:
f1=figure;
t=pi/4;
r=1;
polar(t,r,'.');
dcm_obj = datacursormode(f1);
set(dcm_obj,'UpdateFcn',#polarlabel)
info_struct = getCursorInfo(dcm_obj);
datacursormode on
where polarlabel is defined as follows:
function txt = polarlabel(empt,event_obj)
pos = get(event_obj,'Position');
x=pos(1);
y=pos(2);
[th,r]=cart2pol(x,y);
txt = {['R: ',num2str(r)],...
['\Theta: ',num2str(th*180/pi)]};
Update: This solution is primarily applicable to versions R2014a and older, since it appears to fail for newer versions, specifically R2014b and newer using the new handle graphics system. For newer versions using the new handle graphics system, a solution can be found here.
For some odd reason, the data cursor tool in MATLAB forcibly sets the data tip text to be displayed literally instead of with TeX/LaTeX interpreting (even if the default MATLAB settings say to do so). There also appears to be no way of directly setting text properties via the data cursor mode object properties.
However, I've figured out one workaround. If you add the following to the end of your polarlabel function, the text should display properly:
set(0,'ShowHiddenHandles','on'); % Show hidden handles
hText = findobj('Type','text','Tag','DataTipMarker'); % Find the data tip text
set(0,'ShowHiddenHandles','off'); % Hide handles again
set(hText,'Interpreter','tex'); % Change the interpreter
Explanation
Every graphics object created in the figure has to have a handle. Objects sometimes have their 'HandleVisibility' property set to 'off', so their handles won't show up in the list of child objects for their parent object, thus making them harder to find. One way around this is to set the 'ShowHiddenHandles' property of the root object to 'on'. This will then allow you to use findobj to find the handles of graphics objects with certain properties. (Note: You could also use findall and not worry about the 'ShowHiddenHandles' setting)
Turning on data cursor mode and clicking the plot creates an hggroup object, one child of which is the text object for the text that is displayed. The above code finds this text object and changes the 'Interpreter' property to 'tex' so that the theta symbol is correctly displayed.
Technically, the above code only has to be called once, not every time polarlabel is called. However, the text object doesn't exist until the first time you click on the plot to bring up the data tip (i.e. the first time polarlabel gets called), so the code has to go in the UpdateFcn for the data cursor mode object so that the first data tip displayed has the right text formatting.