1

I have a figure in Matlab, inside the figure i would like to write comments on the figure. the comment include latex formula; for example, I want to write this comment on my figure $$ \vec{R} = 2 $$

here is an example that I found when I searched;

clear all;
close all;
clc;
figure
ms = 8;
fontSize = 18;
xx = 0:.1:1;
plot(xx,sin(xx))
xlabel('P_{fa}', 'fontsize', fontSize);
ylabel('P_{m}', 'fontsize', fontSize);

I want it looks like as in the attached figure below: enter image description here

Note: I searched in last questions that already answered, I found that I can write latex commands in the legend, title, axis ... but not when writing comments inside the figure.

sky-light
  • 111
  • 6

1 Answers1

1

Very easy: just add a text object with its 'interpreter' property set to 'latex':

text(.3, .5, '$\vec R=2$', 'interpreter', 'latex', 'fontsize', fontSize)

The first two arguments of text are coordinates; change them as needed.

enter image description here

Luis Mendo
  • 110,752
  • 13
  • 76
  • 147
  • Thank you very much. This was very useful and nice. I have another question which is also related to the question above: How I can write multi line comment? for example if I want to write $$ R=2; \\ K=3; \\ M=5 $$ not in the same horizontal line, I want them to be vertically listed. I think it can be done by writing several line of the code that you suggested. but I wonder if I can do that using one line command – sky-light Mar 15 '15 at 12:59
  • 1
    It works (at least in Matlab R2014b) if you use a cell array of strings: `text(.3, .5, {'$\vec R=2$', '$K=3$', '$M=5$'}, 'interpreter', 'latex', 'fontsize', fontSize)` – Luis Mendo Mar 15 '15 at 15:44