How can I use '$...$' Environment in xticklabel with matlab2tikz?

1 visualizzazione (ultimi 30 giorni)
Hello,
I am generating a tikzpicture with following Code:
X = 1:1:10;
Y = sin(X);
plot(X,Y);
xticks(X);
xticklabels({'$1$','','$2$','','$3$','','$4$','','$5$',''});
cleanfigure;
matlab2tikz('testfig.tex', 'showInfo', false);
the generated lines for the xticklabels are: (Full Code attached)
xtick={1,2,3,4,5,6,7,8,9,10},
xticklabels={{\$1\$},{},{\$2\$},{},{\$3\$},{},{\$4\$},{},{\$5\$},{}},
Is there a way to tell matlab2tikz, not to interpret the text and exchange $ with \$ but just take it as is?
The compiled Picture looks like this:
For the Y-axis, math font is used, but as labels are often text, for the X-axis the normal text font style is used, why I tried with $$ environment.
So my original Problem is simply, that I dont want every ticklabel to be printed, but have it both in math font style.
I appreciate any help or workaround for this problem. Probably I am missing something as these are my first tries with this package.
Simon

Risposta accettata

Wan Ji
Wan Ji il 29 Ago 2021
Just use
xticklabels({'\$1\$','','\$2\$','','\$3\$','','\$4\$','','\$5\$',''});
rather than
xticklabels({'$1$','','$2$','','$3$','','$4$','','$5$',''});
  2 Commenti
Wan Ji
Wan Ji il 29 Ago 2021
The tiks and ticklabel can be written in
x_tick = X(1:2:end);
xticks(x_tick);
xticklabels(arrayfun(@(i)['\$',num2str(x_tick(i)),'\$'],1:length(x_tick),'uniform',0));

Accedi per commentare.

Più risposte (0)

Prodotti


Release

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by