how to choose a certain color for a string?
Ältere Kommentare anzeigen
I have a text document which contains the word 'hello' how could I write this word in blue,or generally how to set a color for a string in matlab
Antworten (2)
Image Analyst
am 6 Apr. 2016
Use the color option to place your string onto your axes:
text(x, y, yourString, 'Color', 'r');
Color can also be a 3 number array for [r,g,b] with values in the range 0-1 to get any color you want. You can also change font size and font name with appropriate options,
5 Kommentare
jojototo
am 10 Apr. 2016
Image Analyst
am 10 Apr. 2016
Oh, I misunderstood. I thought you were just getting the strings from a document and then you were using MATLAB to display them somewhere, like an axes. If you actually want MATLAB to control your other program, such as Microsoft Word, and then tell Word to change the text properties (color), then you'll have to use ActiveX. Word obviously understands ActiveX but I don't know what program you're using. I'm attaching a demo where I use ActiveX to control Excel. Obviously Excel will have different methods in it and you'll have to figure out what methods Word uses. One of the easiest ways to figure it out is to record a macro "View/Macros/Record Macro..." and then edit the macro and look at the code that got recorded. Then transfer that code back to your MATLAB function.
jojototo
am 5 Jun. 2016
Image Analyst
am 5 Jun. 2016
When I said "View/Macros/Record Macro..." that is doing that from Microsoft Word. Just look at the tool ribbon in Word.

jojototo
am 8 Jun. 2016
Walter Roberson
am 6 Apr. 2016
If you need to set the color inside the text document then you cannot do that: plain text does not have a color.
Changing the color of text can be done in some human-readable formats such as RTF; for example (thanks to pindari.com)
{\rtf1\ansi\deff0
{\colortbl;\red0\green0\blue0;\red255\green0\blue0;}
This line is the default color\line
\cf2
This line is red\line
\cf1
This line is the default color
}
You might be able to set color in Excel files, under some conditions.
4 Kommentare
jojototo
am 10 Apr. 2016
Walter Roberson
am 10 Apr. 2016
What is a "document" for your purpose? I was able to find the list of formatting codes for WordPerfect, for example, but it would take me more digging to find the list of supported colors.
jojototo
am 5 Jun. 2016
per isakson
am 8 Jun. 2016
Bearbeitet: per isakson
am 8 Jun. 2016
Kategorien
Mehr zu Spreadsheets finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!