How can you change the color and size of the elements in the matrix as shown below?

7 views (last 30 days)
label = {' A',' B',' C',' D',' E',' F',' G',' H',' L',' M'}; I have to change the font color of the letters to red and increase the font size to 6.

Answers (2)

Walter Roberson
Walter Roberson on 23 May 2017
If you are referring to plot() of a graph() or digraph() object, then the more obvious customizations are described https://www.mathworks.com/help/matlab/math/graph-plotting-and-customization.html
The label color and size are not in the more obvious customizations, and they are not available through the public properties. However, if you do
p = plot(YourGraphObject);
ps = struct(p); %you will get two warnings that you can ignore
label_handles = ps.NodeLabelHandles_;
Now label_handles is a vector of matlab.graphics.primitive.world.Text objects. These are not the usual matlab.graphics.primitive.Text objects, but you can change their properties, such as
label_handles(1).Font.Size = 12;
There is no foreground Color property for the text, and it is not immediately obvious how to set a foreground color, but it turns out that you can set the ColorData property to a 4 x 1 vector of uint8 (Column vector! uint8!) where the components are R G B alpha.

Jan
Jan on 23 May 2017
Edited: Jan on 23 May 2017
You cannot change the color of the elements of a cell string. Cell strings are cell arrays, which contain CHAR vectors. There is no property concerning the fonts or colors.
But perhaps you want tio display this cell string, perhaps in a popup menu or as text() or uicontrol('Style', 'edit'). Then please read the doc of the corresponding command and if this does not help, edit the question and insert, where and how you want to display the strings.
What is the relation to the tag "djikstra"?
  5 Comments
Walter Roberson
Walter Roberson on 24 May 2017
My answer already explained how to change the font size and color of labels for graph() and digraph() objects.
Jan
Jan on 24 May 2017
Edited: Jan on 24 May 2017
@Anwaya: You still do not answer my question: Where should the colors and font sizes be changed? Which command is used to display the labels? This detail is important for an answer. You cannot change the color of a character or a number, this is simply meaningless. An 'a' is the character 'a' and does not have any font or color. But as soon as you display it, these properties can be set:
text(0.5, 0.5, 'a', 'FontSize', 20)
The code you have shown does not clarify anything, because it does not concern the display at all. So please answer the question:
Where and how do you want to display the labels?
Increase the font size to 6? In Points? 6 is really tiny. Most fonts are evn not readable in 6 pt.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!