Indexing a Text object?

조회 수: 7 (최근 30일)
Jung Woo Kim
Jung Woo Kim 2020년 3월 10일
댓글: Jung Woo Kim 2020년 3월 10일
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
  댓글 수: 1
Jung Woo Kim
Jung Woo Kim 2020년 3월 10일
Thanks a lot-!

댓글을 달려면 로그인하십시오.

추가 답변 (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