Surface plot with LaTeX code in label - matlab

I would like to use the Letter μ (LaTeX: \mu) in my surface plot. Unfortunately when I use the LaTeX symbol \mu in the zlabel('Power [\muW]'); command it results in:
'Power [ μ W]' instead of 'Power [μW]'
How can I avoid these spaces around μ?

I can't reproduce your problem, which could be due to you using an older version of Matlab. In the past it was neccesary to set the latex interpreter fist, before using Latex syntax. So the following should work:
zlabel('Power [$$\mu$$W]','interpreter','latex');
Nowadays it seems to recognize automatically at least greek letters.

Related

How can I write with latex character in xlabel in matlab

I would write my xlabel with Latec character so I used this code
x = -10:0.1:10;
y = [sin(x); cos(x)];
plot(x,y)
xlabel('$\mathbb{x}$','Interpreter','latex')
but I have this warning message
Warning: Error updating Text.
String scalar or character vector must have valid interpreter syntax:
$\mathbb{x}$
and the xlabel appear like this
https://i.stack.imgur.com/NCI4n.png
please how I can fix this problem.
The problem with your example is the mathbb command, which is not in base Latex. To show this, replace the \mathbb with, e.g., \mathrm. This will work.
I've never seen an example of adding Latex packages into the Matlab environment. (Update below)
You can have a look at this question, which includes a very aggressive potential way to add the package you need. But it's not clear to me if the solution proposed is actually functional.
How do you use the LaTeX blackboard font in MATLAB?

How to create a Matlab symbol composition ∆t?

I'd like to create a single symbol which is contains a delta "∆" and a t.
For visualisation purposes i use Matlab Live Script.
Combining several latin letters is easy done by:
sym('dt')
But these either result in an exception or don't do a conversion:
sym('Delta t')
sym('Deltat')
The workaround to multiply two symbols does not work in all cases:
sym('Delta')*sym('t')
(sym('Delta')*sym('t'))^2
However, if i square the symbol, i'd like to have this behavior:
sym('dt')^2
But it should contain the delta symbol:
Is this what you want?
title('\Deltat')
If you want, you can also do
title('\Deltat^{2}')
The answer is no, you cant use non-ASCII for variables in MATLAB. This means no \Delta, no \epsilon, or any other non-standard chars.
You can generate the LaTeX representation of the results, and then print them either in text in MATLAB or in your favourite LaTeX editor with the function latex

How does matlab's latex interpreter handle unicode?

I'm wondering how MATLABs latex interpreter for plot text deals with unicode characters? It is weirdly inconsistent. Which, y'know, invalidates the whole ENTIRE point of unicode.
TOY CODE
%*** Setup some text for a plot title
Title_Txt{1} = [char(8734) ,' SNR~~~' , char(10) , '(-)'];
Title_Txt{2} = ['50 SNR~~~' , char(10) , '(-)'];
%*** Plots!
x= 1:1:10
y= rand(size(x))
figure(1)
subplot(211)
plot(x,y)
title(Title_Txt{1} , 'interpreter' , 'latex')
subplot(212)
plot(x,y)
title(Title_Txt{2} , 'interpreter' , 'latex')
Toy code demonstrates that the latex interpreter handles char(10) --- a new line. But it breaks from char(8734) --- the infinity symbol.
Obviously I can work around this by feeding in a latex symbol that matlab knows (another source of frustration but that's for a different discussion), but I am curious about
what MATLAB is doing under the hood here?
is there is a fix for getting unicode into latex?
I suspect the (unsatisfying) answer here is that the Latex interpreter portion of Matlab does whatever the included version of Latex does, and Latex in general doesn't support Unicode. (For Latex solutions, see: https://tex.stackexchange.com/questions/34604/entering-unicode-characters-in-latex. Of course this doesn't help Matlab users.)
As to why Latex doesn't support Unicode. I'll note that the first copyright date on my Latex users' guide is 1985, and the latest release is version 2e, from 1994. Unicode was not really mainstream until the '90's.
(This is a poor answer, but became too long for a comment.)

Latex changes fonts in Matlab produced eps files

In short:
I produce a figure in matlab (2013a). The problem lies with the "fontname" command. Example code is
plot([1:10],[1:10])
set(gca, 'XTick',[0,4,8])
set(gca, 'XTicklabel',{'p/2','3p/2','2p'},'fontname','symbol');
Prints it with print -despc "filename".
Include it in a latex file with includegraphics command and epstopdf
The fonts in the figure are distorted, while they are intact the eps file itself. For example, in the latex file, the pi labels are turned into not-equal signs.
Do you know why does this happen?
Remark: I have to use "fontname" command because, at least for Matlab 2013a, latex interpreter can not be applied for the XTickLabel.

matlab's phi symbol

Not that significant, but annoying to no end. Why does matlab has no small phi (\varphi) symbol ? It has pretty much all other symbols LaTeX offers, but not this one. Why ?
I may be wrong of course, in which case would be delighted if someone could prove me wrong...
The default interpreter is TeX actually, not LaTeX, which is why you're having this problem. You can use LaTeX as the interpreter for a given part doing something like this:
plot(1);
hl = legend('$$\varphi$$');
set(hl,'Interpreter','latex')
or you can set LaTeX as your default interpretor using
set(0,'DefaultTextInterpreter', 'latex');
which can be put in your startup.m file if you like.
Matlab uses TeX as default. Often, it is possible to switch to LaTeX, but in some cases (dialog boxes), this is impossible.
%# here's an example with all three phis
plot(rand(3))
yh = get(gca,'YLabel');
set(yh,'Interpreter','latex','string','$\varphi$ $\phi$ $\Phi$')