フィルターのクリア

Converting Colour RGB into a string with padding and gaps

2 ビュー (過去 30 日間)
Jason
Jason 2024 年 6 月 18 日
コメント済み: Jason 2024 年 6 月 18 日
Hello, I am accessing the color of lineplots and want to output them to a text area
b=ax.Children;
n=numel(b);
ReportMessage(app,'******* Graphics Objects [RGB] (1=newest) *******');
for i=1:n
T=b(i).Type; %Text or line?
C=b(i).Color %Get line colour
Lg=b(i).DisplayName;
end
These colours "C" are doubles in the form
C =
0 0.4470 0.7410
when i want to create a string from them, if I use this in the loop:
ReportMessage(app,[num2str(i,'%02d'),': ',T,', color: ',num2str(C,'%.2f'),' Lgd: ',Lg]);
I get:
01: line, color: 0.000.450.74 Lgd: 30.0 (^{o}C), 20s Delay
02: line, color: 1.000.540.00 Lgd: 27.5 (^{o}C), 20s Delay
03: line, color: 0.250.800.54 Lgd: 25.0 (^{o}C), 20s Delay
04: line, color: 0.830.140.14 Lgd: 22.5 (^{o}C), 20s Delay
where the colour RGB have no spaces between each component.
How can I get Color, so the 1st line would become (Note I need gaps between the components RGB)
01: line, color: 0.000 0.447 0.741 Lgd: 30.0 (^{o}C), 20s Delay
T
his is my 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

採用された回答

Image Analyst
Image Analyst 2024 年 6 月 18 日
Use sprintf to make up a custom string with the info you want, then use text to place that string somewhere on your GUI.
  1 件のコメント
Jason
Jason 2024 年 6 月 18 日
Thankyou I.A, this worked
formatSpec = 'Color: %.2f %.2f %.2f'; A1=C(1), A2=C(2); A3=C(3);
str = sprintf(formatSpec,A1,A2,A3)

サインインしてコメントする。

その他の回答 (0 件)

製品


リリース

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by