How to display a string array in a figure

조회 수: 19 (최근 30일)
Ethan Scott
Ethan Scott 2019년 11월 27일
답변: Walter Roberson 2019년 11월 27일
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:

채택된 답변

Walter Roberson
Walter Roberson 2019년 11월 27일
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개)

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

제품


릴리스

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by