Graphic Objects Array Items to Text

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