different colors for the title

48 views (last 30 days)
MINA
MINA on 11 Mar 2020
Commented: MINA on 11 Mar 2020
I want to have different colors for different words in the title how can I do that? something like this:
p.col=[0.5 0.5 0.5; 0.1 0.1 0.1];
title({['\color[rgb]{p.color(1,:)','A= ',num2str(A),' \color[rgb] {p.color(2,:)} B= ,num2str(B))]},'fontsize',12)
I don't know how I can give a variable as a color specifier.

Accepted Answer

Ameer Hamza
Ameer Hamza on 11 Mar 2020
You need to carefully compose the string. There are syntax error in your statement. Try
A = 1;
B = 1;
p.col=[1 0 0; 0 0 1];
t = title([ ...
'\color[rgb]{' sprintf('%1.2f,%1.2f,%1.2f', p.col(1,:)) '} A= ' num2str(A), ...
',\color[rgb]{' sprintf('%1.2f,%1.2f,%1.2f', p.col(2,:)) '} B= ' num2str(B)], ...
'fontsize',12, 'Interpreter', 'tex');

More Answers (0)

Community Treasure Hunt

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

Start Hunting!