Fix position of legend in MATLAB - matlab

How do I fix the position of a legend in a MATLAB figure?
I'm currently building a GUI, intended for public use, and when figures inside the GUI are produced I do not want the user to be able to move the legend by click-and-drag. Anyone?

You have to remove the buttonDownFcn from the legend.
snippet:
line(rand(1,3),rand(1,3))
l=legend('location','ne')
set(l,'ButtonDownFcn',[])

Related

How can I prevent objects from blocking ButtonDownFcn callback in a figure?

I have a plot of an image, made with imagesc. I'm developing a workflow where a user can click on the image and interactively overlay a curve. My first issue was that the ButtonDownFcn for the figure is blocked by the image. I worked around this by setting the ButtonDownFcn on the image object instead (and walking back up the parents to get to the figure). Now I'm finding that the curve I'm plotting can also block callbacks intended for the image.
My searches have indicated that I should be able to disable the "hittest" property to prevent the problem, but this has been ineffective for both the image and plotted lines. Suggestions?
Example:
file 1
function testCallback(src,data)
disp('Hello')
file 2
fig = imagesc(rand(100,100));
set(fig,'ButtonDownFcn',#testCallback);
hold on
plot([0 100],[0 100],'m-','linewidth',5,'hittest','off')
Unable to trigger callback when clicking on the line.
You could also set the button down function for the line that you add. Change your plot command to this:
plot([0 100],[0 100],'m-','linewidth',5,'ButtonDownFcn',#testCallback)

Matlab 2016a legend line width

I want to plot the legend in a Matlab figure using R2016a. Sample paint image left is what I get right is what I want:
But the lines inside the legend box are too narrow. How can i make them longer?
Note that I am using Matlab 2016a. I cant get the legend properties and change them with code since when I type:
lgh=legend;
I get that lgh is a matlab.graphics.illustrator. Legend and when I double click it I go to the property inspector where I cant change the width of the lines inside the legend.
You do not have to create an object, you could simply type in >> legend on
on the command window, and legend will be added on the active plot.

Default display of axes in Matlab Gui

I tried using axes for displaying images in Gui.But, before displaying any images, the axes is shown with a plot figure while running the GUI, something like below.
You can see the default axes being displayed. Is there a way to display the axes in running GUI without displaying these plot figures? So that when the image is not displayed in the axes, nothing is displayed. Thanks in advance.
UPDATE 1
I have used 9 axes here, thus the long trail of y axis.
Yes, you can use
axis off
To remove the axes from the empty plots. Then use
axis on
When you actually plot something to bring them back.
Best,

How to specify which axes to plot in a GUI

I am new to GUI. But I have two axes in GUIDE GUI and wish to specify the one to plot a figure, but I can't find handles.axe1 anywhere. Can anyone help me with this?
Since you built your GUI with GUIDE you can easily access the Tag property of each axes in the property inspector.
Once you know the tag of each axes, you can choose where to plot stuff using the first argument of plot:
plot(TagofAxes,x,y)
or using imshow, using the Parent property:
imshow(YourImage,'Parent',TagofAxes)
and so on.

MATLAB Graphing plots with axes

I have been trying to Create a program with the GUI in MATLAB. When I try to plot information with AXES I can not figure out how to do it. I know about the function plot, but I need to be able to re-size and move the plot around in the figure so I can make room for the input uicontrol. I am not sure what to do. Please help.
There are a couple of different ways to tackle this problem. But the way I always choose to do so, is:
hold on:
plot(...), xlim([xmin xmax), ylim(ymin ymax])
This should set your bounds on the axis.
I don't have Matlab at hand right now, but try the following:
To set size of the plot axes inside the figure window use
set(gca,'Position',[left bottom width height])
see Mathworks' site on axes properties