Re: Using handles and editboxes
- From: "Steven Lord" <slord@xxxxxxxxxxxxx>
- Date: Thu, 16 Apr 2009 09:48:01 -0400
"Mark " <mark.irwin@xxxxxxxxxxx> wrote in message
news:gs73ru$ise$1@xxxxxxxxxxxxxxxxxxxxx
I am using an edit box to set the colour of points drawn on a axis.
My edit is called editbox1 and the 'String' = r to make the line red.
What I want to do its create a key to show which colours represent which
datasets by changing the colour of the edit editbox1.
Currently to do this;
I have created a function bgcolor:
function [edit] = bgcolor(editbox)
style = backcol;
if length(backcol)>1
backcol = backcol(1);
end
set(editbox, 'BackgroundColor', backcol);
if backcol == 'k' || backcol == 'b'
set(editbox, 'ForegroundColor', 'white');
else
end
edit = 1;
I call this function by clicking on a button to update.
I pass the handle of the editbox to this function by calling
bgcolor (handles.editbox1);
This works as I want very nicely however i'd prefer to pass just editbox1
to the function and not handles.editbox1.
Then do so.
editbox1 = handles.editbox1;
bgcolor(editbox1);
I tried passing a string bgcolor('editbox1') to the function then editbox
= ['handles.', editbox], but I need to convert from a string to a handle
to use get / set.
You _could_ do this using a slightly different technique, if your bgcolor
function had access to your GUI's handles structure, but it sounds like you
don't want to do that.
I also want to store editbox1 as a string so that I can create a matrix
for the legend, but I can't figure out why data type handles.editbox1 is
to convert to a string. When i assign it to a variable all i get is a
number.
It's a Handle Graphics handle to a uicontrol of Style edit [I would assume,
from the name] in your figure. If you've set the Tag property of the edit
box in your GUI to 'editbox1' [in this case, I think that was done for you
by default when you created the GUI] then you could retrieve that property
inside your bgcolor function and use it as your string.
Can someone tell me what data type handles are and how to convert them to
strings?
A Handle Graphics handle is sort of like the 'phone number' of the Handle
Graphics object. You use the GET and SET functions to ask it for
information about itself or to tell it to change one of its properties. It
doesn't really make sense to change the Handle Graphics handle into a
string, any more than it would make sense for someone to call me
'508-647-7000' [and before you all call this number to figure out whose it
is, it's the main number for The MathWorks HQ.]
I get the impression that you haven't worked very extensively with Handle
Graphics before ... if that's the case, you should read through this section
in the documentation for a short introduction to Handle Graphics:
http://www.mathworks.com/access/helpdesk/help/techdoc/learn_matlab/f3-15974.html
The functions that Sprinceana pointed you to, STR2FUNC and FUNC2STR, are for
use with function handles which are a different type of animal entirely.
Function handles are introduced here:
http://www.mathworks.com/access/helpdesk/help/techdoc/learn_matlab/f4-2525.html#f4-18209
--
Steve Lord
slord@xxxxxxxxxxxxx
.
- Follow-Ups:
- Re: Using handles and editboxes
- From: Mark
- Re: Using handles and editboxes
- References:
- Using handles and editboxes
- From: Mark
- Using handles and editboxes
- Prev by Date: SVMStruct
- Next by Date: TSP
- Previous by thread: Re: Using handles and editboxes
- Next by thread: Re: Using handles and editboxes
- Index(es):
Relevant Pages
|