Indexing a Text object?

9 Ansichten (letzte 30 Tage)
Jung Woo Kim
Jung Woo Kim am 10 Mär. 2020
Kommentiert: Jung Woo Kim am 10 Mär. 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)

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 10 Mär. 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

Weitere Antworten (0)

Kategorien

Mehr zu Graphics Object Properties finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by