Matlab Figure and TextBox

9 ビュー (過去 30 日間)
Matlab2010
Matlab2010 2014 年 10 月 20 日
編集済み: Orion 2014 年 10 月 20 日
I have an image and I do not wish to use legend. Instead I wish to make my own legend.
I wish to have a text box in the image with each of the following on a new line, in bold with a color (red, blue, green)
'val: >0 & < 0.3'
'val: >0.3 & < 1.1'
'val: >1.2 & < 1.9'
How can I apply the below code to achieve this?
mTextBox = uicontrol('style','text');
set(mTextBox,'String',{'\bf Hello World'});
thank you

採用された回答

Orion
Orion 2014 年 10 月 20 日
編集済み: Orion 2014 年 10 月 20 日
Different colors mean different objects.
just use several call to text
load mandrill % demo image in matlab
image(X);
colormap(map)
Mytext = {'val: >0 & < 0.3','b';...
'val: >0.3 & < 1.1','r';...
'val: >1.2 & < 1.9','y'};
for i=1:size(Mytext,1)
mTextBox(i)=text(350,50*i,Mytext{i,1});
set(mTextBox(i),'Color',Mytext{i,2},'FontWeight','bold');
end
here you get 3 text objects stored in mTextBox
you can't have different colors in the same object

その他の回答 (1 件)

Orion
Orion 2014 年 10 月 20 日
Hi,
your image is drawn in an axe. you can just use text
load mandrill % demo image in matlab
image(X);
colormap(map)
Mytext = {'val: >0 & < 0.3';...
'val: >0.3 & < 1.1';...
'val: >1.2 & < 1.9'};
mTextBox=text(350,50,Mytext);
set(mTextBox,'Color','r','FontWeight','bold');
and if you want several texts, use several call to text, with different positions and colors.
  1 件のコメント
Matlab2010
Matlab2010 2014 年 10 月 20 日
thank you. However, this doesnt quite answer my question. I want to show each line of the textbox in a different color (r,b,g). How do I do this?

サインインしてコメントする。

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by