Matlab datatips: no text visible with view([0 90]) - matlab

When I create a surface plot and use view([0 90]), so that I get a nice top-down view of the plot, the datatips are empty, i.e. the text is not visible. See the attached picture. As soon as I move the view a little bit they become visible though. Why is this happening and is there any fix?(1)
I don't really like the workaround to use view([0 90.0001]) instead. I'd rather see a fix than a workaround.
Mind that this doesn't happen when you save the file as a picture.
(1) It has probably something to do with heights. I think that the text height is at the exact same height as the box, which makes it possible that the text is drawn before the box, overwriting the text. I noticed that the box in that view sometimes disappears behind a surface which has a positive z-axis value.

Related

Aligning axes of different sizes within a GUI

I have a trivial question but not able find a effective solution. I hope somebody could help me in this regard.
I currently have 4 different axes in a GUI. ax1(top left) and ax4(bottom left) should be aligned vertically and similarly ax2(top right) and ax4(bottom right) should be aligned vertically. (I have attached a sample image)
ax1 and ax2 are used to show images that are usually larger in size(~512x512) and ax3 & ax4 are used to display images of size ~43x512. Even though I created the axes with x-axis the same size when I display images they change size and not aligned anymore. No matter what images I display, I want the top and bottom images to of same x length and aligned always.
I tried to keep the XLim the same; XData the same but still doesnt work.
Any help is greatly appreciated.
Thanks, Bala
You can use the align function which is used to do just that. The calling syntax is as follows:
align(HandleList,'HorizontalAlignment','VerticalAlignment')
Therefore in you case, you could write something like this (Note that you wrote ax4 twice in your question, I guess you wish to align axes 1-3 and 2-4):
align([handles.ax1 handles.ax3],'VerticalAlignment','none', 'HorizontalAlignment','center')
and likewise for the other 2 axes:
align([handles.ax2 handles.ax4],'VerticalAlignment','none', 'HorizontalAlignment','center')

how to change the position of the output result in GUI

Does any one here have an idea about how to change the position of output in the GUI matlab to be to the right side of the box and not in the center ?
i think I have to change some properties of the result text box
Check this post out: Positioning of figures
The figure Position property controls the size and location of the figure window on the screen. Monitor screen size is a property of the root Handle Graphics object. At startup, the MATLAB software determines the size of your computer screen and defines a default value for Position. This default creates figures about one-quarter of the screen's minimum extent and places them centered left to right, in the top half of the screen.
The Position Vector
MATLAB defines the figure Position property as a vector. So you may use a figure and text into it, e.g.
figure(gcf)
text(offsetX1, offsetX1, ['result 1: ' num2str(result1)])
text(offsetX2, offsetX2, ['result 2: ' num2str(result2)])
Displaying analytical results in a MATLAB GUI
This post talks about adding a static textbox with your results and positioning it.
Move GUI figure to specified location on screen:
Syntax:
movegui(h,'position')
movegui(position)
movegui(h)
movegui
The answer is pretty much trying to cover up the vauge nature of the question

MatLab: displaying figures side by side

As when you use subplot to display plots side by side in the same window, I would like a similar function that can do the same for multiple figures. This works:
subplot(2,2,1)
and I am looking for something like this:
subfigure(2,2,1)
Does a build-in function with this advantage exist?
You could write one such function yourself. The idea is to get the screen size:
get(0,'ScreenSize')
then divide it up into sub-regions according to the input parameters. You would also need to account for margins in-between.
Another idea:
create an invisible figure (preferably same aspect ratio as the screen)
call subplot inside it
capture the position of the created axis
delete figure
scale the position captured to fit the screen size, and use it to create the actual figures.

Adding text annotation to figure programmatically

I would like to add text annotation to a figure from a GUI made with GUIDE. First I plot some data, than when the user clicks on a checkbox I call the text function in the event handler like this:
text(obj.XData(q), obj.YData(q)+10, int2str(q), 'Units', 'pixels');
obj is the line object itself, q is a counter for each point in the plot. It runs without errors, but nothing happens. I suppose I should 'refresh' the axis somehow, but refresh command doesn't help and I haven't found anything in the documentation.
Edit: I have found out that my code was wrong: pixel units correspond to a coordinate system where the origin is the lower-left corner of my axis control, what is not the same as my data coordinate system. I fixed this problem with ds2nfu, and when I paint before plotting everything is fine. But after plotting I see nothing. Is it possible that there is some kind of z-order problem with annotations?
As I mentioned in the comments, you should use the normalized units to place things in the same coordinate system as the data.
Now for the other problem. I'm not sure if this is a z-order issue, but if it is, you can bring the text to the front using UISTACK:
hText = text(x,y,'str');
uistack(hText, 'top')

MATLAB: impoint getPosition strange behaviour

I have a question about the values returned by getPosition. Below is my code. It lets the user set 10 points on a given image:
figure ,imshow(im);
colorArray=['y','m','c','r','g','b','w','k','y','m','c'];
pointArray = cell(1,10);
% Construct boundary constraint function
fcn = makeConstrainToRectFcn('impoint',get(gca,'XLim'),get(gca,'YLim'));
for i = 1:10
p = impoint(gca);
% Enforce boundary constraint function using setPositionConstraintFcn
setPositionConstraintFcn(p,fcn);
setColor(p,colorArray(1,i));
pointArray{i}=p;
getPosition(p)
end
When I start to set points on the image I get results like [675.000 538.000], which means that the x part of the coordinate is 675 and the y part is 538, right? This is what the MATLAB documentation says, but since the image is 576*120 (as displayed in the window) this is not logical.
It seemed to me like, somehow, getPosition returns the y coordinate first. I need some clarification on this.
Thanks for help
I just tried running your code in MATLAB 7.8.0 (R2009a) and had no problems with image sizes of either 576-by-120 or 120-by-576 (I was unsure which orientation you were using). If I left click inside the image, it places a new movable point. It did not allow me to place any points outside the image.
One small bug I found was that if you left-click in the image, then drag the mouse pointer outside the image while still holding the left button down, it will place the movable point outside the image and won't display it, displaying a set of coordinates that are not clipped to the axes rectangle.
I'm not sure of what could be your problem. Perhaps it's a bug with whatever MATLAB version you are using. I would suggest either restarting MATLAB, or clearing all variables from the workspace (except for the image data im).
Might be worth checking to see which renderer you are using (Painter or OpenGL), a colleague showed me some wierd behaviour with point picking when using the OpenGL renderer which went away when using the Painter renderer.
Your code uses the Image Processing Toolbox, which I don't have, so this is speculation. The coordinate system is probably set to the figure window (or maybe even the screen), not the image.
To test this, try clicking points outside the image to see if you can find the origin.