MATLAB Answers

Editing a string

44 views (last 30 days)
Shounak Chakraborty
Shounak Chakraborty on 20 Jun 2012
I have an array and i want to give a string input to a cell of the array. This is easy as long as my string is normal. But, i need to change the font size and bolden the string, and also change the background colour of my cell. Can someone please help me in doing this?

  0 Comments

Sign in to comment.

Answers (1)

Christoph
Christoph on 20 Jun 2012
Hi Shounak,
what kind of cell are you talking about. And where do you want to print it? In my opinion the string itselfs shouldn't contain any style informations. I would set them in the object where you want to print it. For that reason you should read the help file to this object e.g. the property informations about that object.
good luck, CN

  3 Comments

Shounak Chakraborty
Shounak Chakraborty on 21 Jun 2012
i have a matrix.. let m
m{1,1}= ' XYZ ';
now, i want to make XYZ bold and change the background color of cell (1,1) of my matrix m. is it possible to do that just using matlab?
one way is to create an uitable from my matrix, but i need to use java code to edit individual cells, which i am unwilling to.
currently i'm writing the data in excel and editing the excel cell using COM server, but i want my final output in matlab. it would also suffice if you could tell me a way to import the edited cell from excel to matlab. i guess it will be an inefficient way, but i guess i'll have to make do! :(
Christoph
Christoph on 21 Jun 2012
Hi Shounak,
First of all m is not a matrix but a cellarray. it's important to differ those two data-types. How to color a text depends on where you want do display it. If you want to return it in the CommandWindow I don't know how to do this. But I know that it has to be possible just because an Error occours in red and a Warning in orange.
If you are using a figure to display your strings, you could use the command text(). It's pretty easy to color text. Just take a look to the text-properties in the documentation.
The next way , as you said before, is using an uitable. Don't be afraid of the "java" code. Coloring the font of all cells it not that hard, but coloring only the string of one cell seems to be a challenge. The problem with uicontrol objects in general is, that you can't use any text interpreter. For that reason its not possible to set the string color in the string itself.
To excel question i don't have a clue, just because I never did it. But many other user converte matlab data to excel and the other way around. I guess you should find some answers.
kind regards, CN
Walter Roberson
Walter Roberson on 21 Jun 2012
Christoph is correct that font, bold, color are display attributes and are not part of a string itself.
Coloring individual cells in uitable:
http://www.mathworks.com/matlabcentral/answers/41173-changing-color-of-a-string-in-listbox-matlab-gui

Sign in to comment.

Sign in to answer this question.