Graphic Objects Array Items to Text
Show older comments
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.
Accepted Answer
More Answers (1)
Mario Malic
on 22 Mar 2023
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.
Categories
Find more on Creating, Deleting, and Querying Graphics Objects in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!