I want to insert a textbox in a given location of a figure
and write some desciption in it, there is no edge in the
textbox. I know how to do this manually, but don't know how
to do this with script.
Thanks,
James
Subject: Re: how to insert textbox and write text in a figure by code (not manually)
% Create a uicontrol of type "text"
mTextBox = uicontrol('style','text')
set(mTextBox,'String','Hello World')
% To move the the Text Box around you can set and get the position of Text
Box itself
mTextBoxPosition = get(mTextBox,'Position')
% The array mTextBoxPosition has four elements
% [x y length height]
% Something that I find useful is to set the Position Units to Characters,
the default is pixels
set(mTextBox,'Units','characters')
% This means a Text Box with 3 lines of text will have a height of 3
-Scott
"James Anderson" <janderson_net@yahoo.com> wrote in message
news:fa1nue$lhh$1@fred.mathworks.com...
> Hi,
>
> I want to insert a textbox in a given location of a figure
> and write some desciption in it, there is no edge in the
> textbox. I know how to do this manually, but don't know how
> to do this with script.
>
> Thanks,
>
> James
Subject: Re: how to insert textbox and write text in a figure by code (not manually)
Thanks for your reply, it works! One additional question is
that how to set the background color of the textbox to be
transparent as if there is no box frame, but still with
strings.
I used the following command:
set(mTextBox,'BackgroundColor',[1 1 1])
but don't know what's the corresponding 3 numbers for
transparent, or I should set some other properties instead
of background to do this?
Many thanks,
James
"Scott Frasso" <scott.frasso@mathworks.com> wrote in message
<fa1qs8$83n$1@fred.mathworks.com>...
> Hello James,
>
> % Create the figure
> mFigure = figure()
>
> % Create a uicontrol of type "text"
> mTextBox = uicontrol('style','text')
> set(mTextBox,'String','Hello World')
>
> % To move the the Text Box around you can set and get the
position of Text
> Box itself
> mTextBoxPosition = get(mTextBox,'Position')
> % The array mTextBoxPosition has four elements
> % [x y length height]
>
> % Something that I find useful is to set the Position
Units to Characters,
> the default is pixels
> set(mTextBox,'Units','characters')
> % This means a Text Box with 3 lines of text will have a
height of 3
>
> -Scott
>
> "James Anderson" <janderson_net@yahoo.com> wrote in message
> news:fa1nue$lhh$1@fred.mathworks.com...
> > Hi,
> >
> > I want to insert a textbox in a given location of a figure
> > and write some desciption in it, there is no edge in the
> > textbox. I know how to do this manually, but don't know how
> > to do this with script.
> >
> > Thanks,
> >
> > James
>
>
Subject: Re: how to insert textbox and write text in a figure by code (not manually)
Jeff:
<SNIP wants to set his/her subplot axes manually...
> Can you set the position to a subplot index instead of a
certain x,y location...
yes, but with limitations...
% look at this example
pos=[
.1,.1,.3,.3
.4,.4,.3,.3
];
subplot(2,2,[1,2]);
for i=1:size(pos,1)
subplot('position',pos(i,:));
pause
end
% so - a new subplot removes all others underneath it...
% a better solution
% get pos of a subplot
figure;
sh=subplot(2,2,1);
pos=[
get(sh,'position')
pos
];
delete(sh); % not necessary...
ah=zeros(size(pos,1),1);
for i=1:size(pos,1)
ah(i)=axes('position',pos(i,:));
end
axes(ah(1)); % make axis one active...
us
Subject: Re: how to insert textbox and write text in a figure by code (not manually)
Another question I forget to ask is that in the command:
set(mTextBox,'String','Hello World')
is there any way to set the string to a two-line text so
that the first line is empty and the second line is "hello
world"? I tried several times but seems that it only works
for one line.
Thanks,
James
"Scott Frasso" <scott.frasso@mathworks.com> wrote in message
<fa1qs8$83n$1@fred.mathworks.com>...
> Hello James,
>
> % Create the figure
> mFigure = figure()
>
> % Create a uicontrol of type "text"
> mTextBox = uicontrol('style','text')
> set(mTextBox,'String','Hello World')
>
> % To move the the Text Box around you can set and get the
position of Text
> Box itself
> mTextBoxPosition = get(mTextBox,'Position')
> % The array mTextBoxPosition has four elements
> % [x y length height]
>
> % Something that I find useful is to set the Position
Units to Characters,
> the default is pixels
> set(mTextBox,'Units','characters')
> % This means a Text Box with 3 lines of text will have a
height of 3
>
> -Scott
>
> "James Anderson" <janderson_net@yahoo.com> wrote in message
> news:fa1nue$lhh$1@fred.mathworks.com...
> > Hi,
> >
> > I want to insert a textbox in a given location of a figure
> > and write some desciption in it, there is no edge in the
> > textbox. I know how to do this manually, but don't know how
> > to do this with script.
> >
> > Thanks,
> >
> > James
>
>
Subject: Re: how to insert textbox and write text in a figure by code (not manually)
In article <fa45ci$j9b$1@fred.mathworks.com>,
James Anderson <janderson_net@yahoo.com> wrote:
>Another question I forget to ask is that in the command:
>set(mTextBox,'String','Hello World')
>is there any way to set the string to a two-line text so
>that the first line is empty and the second line is "hello
>world"? I tried several times but seems that it only works
>for one line.
set(mTextbox,'String',{'', 'Hello World'})
You will also find that in some contexts (e.g., -some- uicontrol
styles), you can use '|' to mark the end of lines
set(controlhandle,'String', '|Hello World');
and in some contexts, you can use \n between lines
--
"It is important to remember that when it comes to law, computers
never make copies, only human beings make copies. Computers are given
commands, not permission. Only people can be given permission."
-- Brad Templeton
Subject: Re: how to insert textbox and write text in a figure by code (not manually)
<how to set the background color of the textbox to be
transparent as if there is no box frame, but still with
strings.>
You can set the background color of the Text Box to the same color as the
Figure window by getting the figure windows "Color" value and applying it to
the "BackgroundColor" of the Text Box.
% Get the Color of the figure window
colorOfFigureWindow = get(mFigure,'Color');
%Set the BackgroundColor of the text box
set(mTextBox,'BackgroundColor',colorOfFigureWindow)
-Scott
"James Anderson" <janderson_net@yahoo.com> wrote in message
news:fa23eo$rtk$1@fred.mathworks.com...
> Scott,
>
> Thanks for your reply, it works! One additional question is
> that how to set the background color of the textbox to be
> transparent as if there is no box frame, but still with
> strings.
>
> I used the following command:
> set(mTextBox,'BackgroundColor',[1 1 1])
> but don't know what's the corresponding 3 numbers for
> transparent, or I should set some other properties instead
> of background to do this?
>
> Many thanks,
>
> James
>
>
>
> "Scott Frasso" <scott.frasso@mathworks.com> wrote in message
> <fa1qs8$83n$1@fred.mathworks.com>...
>> Hello James,
>>
>> % Create the figure
>> mFigure = figure()
>>
>> % Create a uicontrol of type "text"
>> mTextBox = uicontrol('style','text')
>> set(mTextBox,'String','Hello World')
>>
>> % To move the the Text Box around you can set and get the
> position of Text
>> Box itself
>> mTextBoxPosition = get(mTextBox,'Position')
>> % The array mTextBoxPosition has four elements
>> % [x y length height]
>>
>> % Something that I find useful is to set the Position
> Units to Characters,
>> the default is pixels
>> set(mTextBox,'Units','characters')
>> % This means a Text Box with 3 lines of text will have a
> height of 3
>>
>> -Scott
>>
>> "James Anderson" <janderson_net@yahoo.com> wrote in message
>> news:fa1nue$lhh$1@fred.mathworks.com...
>> > Hi,
>> >
>> > I want to insert a textbox in a given location of a figure
>> > and write some desciption in it, there is no edge in the
>> > textbox. I know how to do this manually, but don't know how
>> > to do this with script.
>> >
>> > Thanks,
>> >
>> > James
>>
>>
>
Public Submission Policy
NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for
all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content.
Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available
via MATLAB Central. Read the complete Disclaimer prior to use.