How to display a string array in a figure
19 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Ethan Scott
le 27 Nov 2019
Réponse apportée : Walter Roberson
le 27 Nov 2019
I would like to display the contents of a string array in a figure (for example, showing a table of parameters used in a model fit).
To accomplish this, I have tried to display the contents as a string array in an annotation over top the figure. For example, I plot some function into a figure, then add an annotation which is a string array of the values I want to display. The main issue I am experiencing is that the array displays top down intead of as an actual array (i.e. it displays the values in a vertical line rather than say a 3x5 matrix).
My question is: how can I get the contents of the string array to display as a matrix in the annotation rather than a vertical display of the contents of the array?
Here is a minimal working example of the issue:
x = linspace(0,1);
plot(x,cos(x));
header = ["symbol_1" "symbol_2" "symbol_3" "symbol_4" "symbol_5"];
values = [1 2 3 4 5; 6 7 8 9 10];
array = [header;values];
annotation('textbox',[.15 .15 0.5 0.5],'string',array);
Here is what the code produces:

Here is what I'd like to produce:

0 commentaires
Réponse acceptée
Walter Roberson
le 27 Nov 2019
Set the annotation Interpreter to latex, and use latex matrix constructions, such as https://www.mathworks.com/matlabcentral/answers/280414-latex-in-live-scripts-using-matrix
For example ''$\pmatrix{1 & 2 \cr 3 & 4}$''
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Matrices and Arrays dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!