find all graphic objects that have a spesific word in their handle (even if it is part of the full name of the handle) - matlab

I am trying to find all the color-related graphic objects of a general matlab figure.
For example, if I look at
polarplot(rand(4))
h=gca;
I find that it has the handles Color , RColor, ThetaColor, etc, as well as in its children, for example, h.Children(1).Color, h.Children(1).MarkerEdgeColor, etc...
Is there an efficient way to find all these according to word Color when using findobj \ findall or a similar function with some type of regex?

Related

Matching two distinct images with similar SURF features matlab

We are working upon gesture to text conversion using matlab and want the input gesture from user to be mapped with a predefined database. Using detectsurffeatures function, we extract the features, but proper matching is not taking place unless input is a part of the reference image
How to map the features the pairs like...
input hand and database
We are not getting any error, yet the images are not mapped.
Please suggest a solution.

Change label of data tips on bode nichols diagram

When we plot a bode/nichols locus, the name of workspace variable is used
tmp=ss(1,1,1,0);
nichols(tmp);
will use 'tmp' as label.
When using more complex data, matlab is using 'untitled1','untitled2',...
tmp={ss(1,1,1,0) , ss(1.2,1,1,0)};
nichols(tmp{:});
How can I change this label programmatically?
Ideally, I'd like a solution working with Matlab 6.5.1, but I'm also interested in solutions restricted to newer versions.
You can modify the labels programmatically via their graphics handles. It looks like the values you want to change are the DisplayName property of some of the children of the current axis. So in your first example, I can change the display name like this:
ch = get(gca,'Children');
set(ch(1),'DisplayName','Fred');
In general, I'm not sure how to predict which children of the current axis are the ones you need to change. For the second example you give, the two curves appear to be the second and third children when I run your code.

Find tag matlab gui

I am reading another programmer's Matlab GUI. It is really complicated. A lot of axes and bars and tables. When I look deeper into the .m file, I just cannot find the corresponding parts in the .fig layout. Is there any good way to do that?
Thanks.
There is the findall function:
object_handles = findall(handle_list) returns the handles, including hidden handles, of all objects in the hierarchy under the objects identified in handle_list.
For instance, you might call findall(gcf, 'Type', 'Text') to find all text objects etc.
Also, there is the findobj:
Locate graphics objects with specific properties

Matlab: Adding symbols to figure

Below is the user interface I have created to simulate LDPC coding and decoding
The code sequence is decoded iteratively by passing values between the left and right nodes through the connections.
The first thing it would be good to add in order to improve visualization is to add arrows to the connections in the direction of passing values. The alternative is to draw a bigger arrow at the top of the connection showing the direction.
Another thing I would like to do is displaying the current mathematical operation below the connection (in this example c * H'). What I don't know how to do is displaying special characters and mathematical symbols and other kinds of text such as subscript and superscript in the figure (for example sum sign and subscript "T" instead of sign ="'" to indicate transposed matrix).
I would be very thankful if anyone could point to any useful resources for the questions above or show the solution.
Thank you.
To add arrows, you can either use the built-in QUIVER, or, for more options, ARROW from the file exchange. Both of these have to be plotted into axes, so if you want a big arrow on the top, you have to create an additional set of axes above the main axes.
As far as I know, you cannot use TeX or LaTeX symbols in text uicontrols. However, you can use them in axes labels. Thus, I suggest that you add an XLabel to the axes, for example
xlabel('\sigma c*H_T')
or (note the $-signs required for LaTeX)
xlabel('$\sum c*H_T$','interpreter','latex')
EDIT
I hadn't mentioned the use of text (as suggested by #gnovice and #YYC) because I thought it wasn't possible to place text outside of the axes. It turns out that I was wrong. text(0.5,-0.2,'\Sigma etc.') should work fine as well. I guess the only advantage of using 'xlabel' would be that you can easily add and position the axes label during GUI creation.
In regards to the 1st question, annotation (http://www.mathworks.com/access/helpdesk/help/techdoc/ref/annotation.html) might be an alternative solution.
In regards to the 2nd question, try text property in Matlab Help.
Search "Character Sequence" for the special characters; search "Specifying Subscript and Superscript Characters" for the subscript and superscript.
For drawing the arrow, I would go Jonas' suggestion arrow.m by Erik Johnson on the MathWorks File Exchange. It's the easiest way I've found to create arrows in figures.
For creating text with symbols, you can use the function TEXT. It lets you place text at a given point in an axes, and you can use the 'tex' (default) or 'latex' options for the 'Interpreter' property to get access to different symbols. For example, this places the text you want at the point (0,0) using 'latex' as the interpreter:
hText = text(0,0,'$\sum c*H_T$','Interpreter','latex');
The variable hText is a handle to the text object created, which you can then use with the SET command to change the properties of the object (string, position, etc.).

How do I use TeX/LaTeX formatting for custom data tips in MATLAB?

I'm trying to annotate a polar plot with data tips labelled with 'R:...,Theta:...' where theta is actually the Greek symbol, rather than the word spelled out. I'm familiar with string formatting using '\theta' resulting in the symbol, but it doesn't work in this case. Is there a way to apply the LaTeX interpreter to data tips? Here's what I have so far:
f1=figure;
t=pi/4;
r=1;
polar(t,r,'.');
dcm_obj = datacursormode(f1);
set(dcm_obj,'UpdateFcn',#polarlabel)
info_struct = getCursorInfo(dcm_obj);
datacursormode on
where polarlabel is defined as follows:
function txt = polarlabel(empt,event_obj)
pos = get(event_obj,'Position');
x=pos(1);
y=pos(2);
[th,r]=cart2pol(x,y);
txt = {['R: ',num2str(r)],...
['\Theta: ',num2str(th*180/pi)]};
Update: This solution is primarily applicable to versions R2014a and older, since it appears to fail for newer versions, specifically R2014b and newer using the new handle graphics system. For newer versions using the new handle graphics system, a solution can be found here.
For some odd reason, the data cursor tool in MATLAB forcibly sets the data tip text to be displayed literally instead of with TeX/LaTeX interpreting (even if the default MATLAB settings say to do so). There also appears to be no way of directly setting text properties via the data cursor mode object properties.
However, I've figured out one workaround. If you add the following to the end of your polarlabel function, the text should display properly:
set(0,'ShowHiddenHandles','on'); % Show hidden handles
hText = findobj('Type','text','Tag','DataTipMarker'); % Find the data tip text
set(0,'ShowHiddenHandles','off'); % Hide handles again
set(hText,'Interpreter','tex'); % Change the interpreter
Explanation
Every graphics object created in the figure has to have a handle. Objects sometimes have their 'HandleVisibility' property set to 'off', so their handles won't show up in the list of child objects for their parent object, thus making them harder to find. One way around this is to set the 'ShowHiddenHandles' property of the root object to 'on'. This will then allow you to use findobj to find the handles of graphics objects with certain properties. (Note: You could also use findall and not worry about the 'ShowHiddenHandles' setting)
Turning on data cursor mode and clicking the plot creates an hggroup object, one child of which is the text object for the text that is displayed. The above code finds this text object and changes the 'Interpreter' property to 'tex' so that the theta symbol is correctly displayed.
Technically, the above code only has to be called once, not every time polarlabel is called. However, the text object doesn't exist until the first time you click on the plot to bring up the data tip (i.e. the first time polarlabel gets called), so the code has to go in the UpdateFcn for the data cursor mode object so that the first data tip displayed has the right text formatting.