Indexing a Text object?

7 次查看(过去 30 天)
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)

采纳的回答

Walter Roberson
Walter Roberson 2020-3-10
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

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Graphics Object Properties 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by