フィルターのクリア

Graphic Objects Array Items to Text

14 ビュー (過去 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 Center および File ExchangeGraphics Object Programming についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by