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
% 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" <jander...@yahoo.com> wrote in message
news:fa1nue$lhh$1...@fred.mathworks.com...
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....@mathworks.com> wrote in message
<fa1qs8$83n$1...@fred.mathworks.com>...
Can you set the position to a subplot index instead of a certain x,y location?
ie:
subplot(2,2,1);
% plot 1
subplot(2,2,2);
% plot 2
subplot(2,2,3);
% plot 3
subplot(2,2,4);
% textbox
> 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
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....@mathworks.com> wrote in message
<fa1qs8$83n$1...@fred.mathworks.com>...
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
set(somehandle, 'String', sprintf('\nHello World') );
--
"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
<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" <jander...@yahoo.com> wrote in message
news:fa23eo$rtk$1...@fred.mathworks.com...
This works for me:
text('Position',[0 1],'string','Hello World')
Thanks
"James Anderson" <jander...@yahoo.com> wrote in message <fa1nue$lhh$1...@fred.mathworks.com>...