Graphic Objects Array Items to Text

조회 수: 9 (최근 30일)
Jason
Jason 2023년 3월 22일
답변: Jason 2023년 3월 22일
Hello. I want to view all the graphics objects I have on a UIAxes, and have used the following in an attempt to output all the items to a text area.
clc;
ax=app.UIAxes;
b=ax.Children % b(1) is last object added to uiaxes
class(b(1)) % Check class of 1st item
n=numel(b); % Count of items on UIAxes
for i=1:n
ReportMessage(app,'******* Graphics Objects *******');
% ReportMessage(app,b(i)); %This doesn't work, so try char
ReportMessage(app,char(b(i)));
end
This is my own "ReportMessage" function:
function ReportMessage(app,msg)
currString=get(app.MessagesTextArea,'Value');
%currString=[{char(msg)};currString]; %add to top of message box
currString=[currString; {char(msg)}]; %add to bottom of message box
app.MessagesTextArea.Value=currString;
drawnow;
scroll(app.MessagesTextArea,'bottom');
end
But I'm struggling to convert the graphics item to a string, I haven't found anything searching google.
b =
4×1 graphics array:
Text (\leftarrowy = 0.0000x^2 + -0.0002x + 1.5175)
Line
Line
Line
ans =
'matlab.graphics.primitive.Text'
n =
4
Error using char
Conversion to char from matlab.graphics.primitive.Text is not possible.

채택된 답변

Jason
Jason 2023년 3월 22일
Heres the full answer:
clc;
ax=app.UIAxes;
b=ax.Children; % b(1) is last object added to uiaxes
n=numel(b);
ReportMessage(app,'******* Graphics Objects [RGB] (1=newest) *******');
for i=1:n
T=b(i).Type; % Get object type (i.e. line, text)
C=b(i).Color; % Get colour of object [R G B] format
ReportMessage(app,[num2str(i),': ',T,', color: ',num2str(C)]);
end
drawnow;

추가 답변 (1개)

Mario Malic
Mario Malic 2023년 3월 22일
Hello,
Text is a component(object) and it has String property which contains the actual text. Keep in mind that b is an array and you will have to get the text component only as other elements do not have the same properties. Correct way in your case should be
b(1).String
You can also use findall function just to find objects of particular type in your graphic objects.
  댓글 수: 2
Jason
Jason 2023년 3월 22일
Hi, thanks for your post. So I have tried your suggestion:
clc;
ax=app.UIAxes;
b=ax.Children % b(1) is last object added to uiaxes
class(b(1))
n=numel(b);
for i=1:n
ReportMessage(app,'******* Graphics Objects *******');
ReportMessage(app,b(i).String);
end
But get the following:
Unrecognized method, property, or field 'String' for class 'matlab.graphics.chart.primitive.Line'.
Jason
Jason 2023년 3월 22일
It looks like "Type" is what I need i.e.
ReportMessage(app,b(i).Type);

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

카테고리

Help CenterFile Exchange에서 Graphics Performance에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by