How to combine Space and dot expressions in Matlab?

1 view (last 30 days)
I'm trying to include blank spaces and a dot above the greek letter psi in one label.
The command for allowing spacing is (with missing dot above psi):
plot(1:10)
ylab = sprintf('$\\psi%s [deg/s]$', repmat('\ ',1,1));
ylabel(ylab,'interpreter','latex');
The command for doing dots above a letter in tex is:
plot(1:10)
ylabel('$\dot{\phi}$', 'Interpreter','latex')
How do i combine those two?
Extra question: Is it possible to exclude the "[deg/s]" from the latex interpreter, so that it has the normal font of matlab plots and only the greek letter is in latex?
Kind regards, Sebastian

Answers (1)

Bjorn Gustavsson
Bjorn Gustavsson on 21 Jan 2021
This seems to work:
ylab = sprintf('$\\dot{\\psi}%s [deg/s]$', repmat('\ ',1,12));
ylabel(ylab,'interpreter','latex');
Do you want something else?
HTH
  2 Comments
Sebastian Konsek
Sebastian Konsek on 21 Jan 2021
Thank you, this helps a lot.
- Sure, if you ask for it:
the "[deg/s]" part ist interpreted in latex, too.
How can i display it with the same font as the default matlab interpreter?
Bjorn Gustavsson
Bjorn Gustavsson on 21 Jan 2021
Ah, that I don't know. Others might be far more clever with font-manipulation when it comes to labels.
I found this (slightly discouraging) answer (from 2011, so a fair number of releases ago): latex-interpreter-different-fonts. After looking around I found more bad(?) news, but perhaps something from dpb's latex-interpreter-font-answers can get you some threads to follow, then there might be something in Yair Altman's undocumentedmatlab on latex and fonts. It is not clear to me how much of standard latex font-handling (LaTeX/Fonts) that you can cram into an ylabel-call...
This seems to work for legend-manipulation:
[l1,l2] = legend({'$\mathrm{Roman here}$','$\mathsf{SanSerif here}$','$\mathit{Italics here}$'});
set(l1,'Interpreter','latex')
set(l2(1:3),'Interpreter','latex')
(this seems like fun for the whole family...)
If you find a great, or even "good enough" solution please let us know!
HTH

Sign in to comment.

Products


Release

R2019b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!