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)
댓글 수: 0
채택된 답변
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 Center 및 File Exchange에서 Graphics Object Properties에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!