Indexing a Text object?
12 views (last 30 days)
Show older comments
Jung Woo Kim
on 10 Mar 2020
Commented: Jung Woo Kim
on 10 Mar 2020
Hi all,
I've made a code like below to make a circular array of words.
I wanted to grab certain part of Text objext(variable 'texts' in below) and change the color of it.
% myFields : cell array that contains the words I need to plot.
% numMF = numel(myFields);
x3 = linspace(0, 360 - (360/numFF), numMF);
for i = 1:numMF
scatter(cosd(x3(i))/2, sind(x3(i))/2, 'MarkerFaceColor', 'white', 'MarkerEdgeColor', 'white');
if x3(i) < 90 || x3(i) > 270
text(cosd(x3(i)), sind(x3(i)), myFields(i), ...
'FontSize', sortidx3(i), 'Rotation', x3(i), 'Interpreter', 'none');hold on
else
text(cosd(x3(i)), sind(x3(i)), myFields(i), ...
'FontSize', sortidx3(i), 'Rotation', x3(i) + 180, 'Interpreter', 'none', 'HorizontalAlignment', 'right');hold on;
% the code nested in else is for rotation of words since words get reversed.
end
end
set(gcf, 'Color', 'white');
set(gca, 'XColor', 'none', 'Ycolor', 'none');
texts = findobj(gcf, 'Type', 'text')
%% texts: Text object that contains the whole words in the figure(gcf)
Say, if texts object looks like below, I want to grab only (a1, a7, a10, a17) and chage the color of those. Any good idea for this? Thanks!
texts =
Text (a1)
Text (a2)
Text (a3)
...
Text (a24)
0 Comments
Accepted Answer
Walter Roberson
on 10 Mar 2020
You cannot do that directly. However if you change Interpreter to tex or latex then you can change the string to use tex or latex notation including color information. https://www.mathworks.com/matlabcentral/answers/278997-matlab-label-with-different-colors-on-the-string-using-latex-interpreter
More Answers (0)
See Also
Categories
Find more on Graphics Object Properties in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!