How do you color text within Matlab?

7 views (last 30 days)
Jaime
Jaime on 24 Sep 2013
Hello, I am trying to gain some more experience with Matlab but I am currently stuck on one of my examples.
The function defined in the file ColouredWordM.m accepts three arguments: a string, a 2-element array specifying a position and a 3-element array specifying a colour. It displays the word in a Matlab figure window whose coordinate system has the origin (0,0) at the bottom left corner of the window extending upwards and rightwards to coordinates of (1.0, 1.0) at the upper right corner of the window.
Write a function that uses ColouredWordM to display the words ‘Red’, Green, Blueand ‘Purple’ arranged vertically and each written in the colour specified by their name (so the word ‘Red’ should be coloured red, below it should be the word ‘Green’ written in green and so on).
This is the information that was given in the Mfile-
function ColouredWordM(stringToDisplay, position, rgbTriplet)
% Presents the string in the first argument in the centre of the screen
% The second argument (e.g. [1.0, 0.0, 0.0]) sets the colour of the string
% The background is set to a mid-grey
text('Position',position,'String',stringToDisplay,'Color',rgbTriplet,'FontSize',20,'HorizontalAlignment','center');
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
Any help would be greatly appreciated!

Answers (1)

Walter Roberson
Walter Roberson on 24 Sep 2013
You all upon the provided ColouredWordM routine to do the work for you.

Categories

Find more on Characters and Strings 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!