Converting Colour RGB into a string with padding and gaps

조회 수: 3 (최근 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개)

카테고리

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

제품


릴리스

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by