How to pass a variable with latex interpreter in the legend?
Afficher commentaires plus anciens
I am mentioning the relevant part of the code below. r_Fit is supposed to be a variable. How do I pass its value in the legend with a mathematical expression, $\tau = $ attached to it? Please help.
a_Fit = output_parameters(1);
r_Fit = output_parameters(2);
r_Fit_Str = num2str(r_Fit);
N_AS_Above3_Fit = a_Fit.*N_Days.^(-r_Fit);
figure(002);
plot(N_Days, N_AS_Above3, '+', 'LineWidth', 3, 'MarkerSize', 14, 'MarkerEdgeColor', 'r');
hold on;
plot(N_Days, N_AS_Above3_Fit, 'k', 'LineWidth', 3);
lgd = legend({'$M>3$', '$\tau = $ r_Fit'}, 'interpreter', 'latex');
Réponse acceptée
Plus de réponses (1)
Dyuman Joshi
le 4 Déc 2023
Modifié(e) : Dyuman Joshi
le 4 Déc 2023
Note that added \ before \tau.
str = compose(['$\\tau = $ %f'], r_fit)
str = [{'$M>3$'} str];
legend(str, 'interpreter', 'latex');
Change the modifier according to the data-type and according to the number of digits you want to show.
4 commentaires
Vikash Pandey
le 4 Déc 2023
Dyuman Joshi
le 4 Déc 2023
There's a missing + sign -
% v
lgd = legend(["$M>3$", "$\tau = $ " + a_Fit + " $p = $ " + r_Fit], 'interpreter', 'latex');
Vikash Pandey
le 4 Déc 2023
Dyuman Joshi
le 4 Déc 2023
You're welcome!
Catégories
En savoir plus sur Surrogate Optimization dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!