Matlab: How to interact with a graph to define a range via GUIs - matlab

I'm currently trying to make a GUI that will allow a user to select a range of x-values, limited to a set of predefined "markers" that can appear on the graph of some data. The Matlab program has a bunch of data that's already delimited with some number of markers, and will ask the user to choose two of these markers as a start and stop point, and then continue from there.
My question is whether or not Matlab has a built-in function or object that will place some kind of interactive marker on the plot (preferably on the bottom of the graph so that it doesn't obscure the data) that the user can click on so that I can get a call-back function from it and see which marker the user chose (and also perhaps have the ability to change its color and such to represent its selection).
Preferably the answer will not involve any add-ons, but any answer and any help would be greatly appreciated. Thank you!

Here is a very simple example using ginput, which asks the user to select a starting and ending points from which to plot the data.
clear
clc
close all
x = 1:15*pi;
figure
plot(x,sin(x),'LineWidth',2);
uiwait(msgbox('Select a start and finish point'))
a = zeros(1,2);
[a,~] = ginput(2);
xStart = a(1);
xFinish = a(2);
set(gca,'XLim',[xStart xFinish],'XTick',round(xStart):1:round(xFinish))
Is it something like this you had in mind? Do you really need a callback or is this sufficient? If not could you elaborate on what kind of markers you would need?
Hope that helps!

Related

Matlab Get Handle for Layout

As the title states, I need to get a handle for my Matlab application. My class is derived from matlab.apps.AppBase and is app.UIFigure (if that matter, I'm still learning Matlab). My main goal is to change the mouse cursor to watch after a button is clicked and data is processed in the background.
I have tried:
set(gcf,'Pointer','watch')
But gcf is just empty, so it creates a new figure. I have also gotten all of the figures, using:
figs = findall(groot,'Type','Figure')
Which finds all of the figures I am using. I believe that I need to get the overall application figure and find the handle, but I am unsure how to do that.
There is no pointer property for uifigure; otherwise, you would be able to use app.UIFigure.Pointer = 'watch' as suggested by #CrisLuengo.
However, specially for uifigure MATLAB provides a nice looking and powerful progress bar uiprogressdlg. You can make it indeterminate with uiprogressdlg.Indeterminate = on;. I find this working pleasingly well.
Here is an example:
f=uifigure;
progressdlg=uiprogressdlg(f,'Title','Progress','Message', 'Doing something please wait', 'Indeterminate','on');
pause(10); % Run your algorithm.
% Delete the progress bar after work done.
progressdlg.delete();

Matlab GUI, create two tabs

I want to create two tabs within one GUI. One can show the plot of sine function, the other shows cone function. I can handle these two functions. but i do not know how to create two tabs. Thanks a lot!
If by tabs you mean 'plotting area' then you likely need to create 2 axes objects and display each plot in its own axes. In GUIDE it's very easy...more info here.
Let's say you have axes1 and axes2, you can do this:
axes(axes1) % Make axes1 the current axes.
plot(sin(...))
axes(axes2) % Make axes2 the current axes
plot(...)
and that's it. Hope this is what you mean! If not sorry I misunderstood the question.
EDIT
I thought about it and I'm probably wrong about what I thought a tab is. Matlab does not allow to do it directly, although it might be possible with the GUI Layout Toolbox. Here is a submission from the FIle Exchange which could be interesting to you: link here!. Sorry abut the confusion.
uitab() can be used for creating tabs. If you want to create tabs using guide it's currently not natively supported but possible with a work around I described here.

MATLAB: Changing plotperform window name, and more

So I'm working on some simple neural network problems for a class I'm taking, and I've mostly done all of the work.
However, I'd like to be able to press run and have all of the relevant figures and graphs pop out so I can easily show my work.
To do this I've been drawing setting the names of figures that I plot in using the
figure('Name', 'NameGoesHere', 'NumberTitle', 'off')`
variant of the figure function.
The thing is, one of the things that I have to show are performance graphs for the different networks I made, and using plotperform(tr) sets the window name to Performace (plotperform) even if I try setting the figure name to something else. Any help?
Here's a picture showing what I mean:
Oh, and, being really new to Matlab, correct me if I'm wrong, but since performance is defined as mean absolute error, the lower it is, the better right? So is there a way to set is so plotperform actually selects the lowest point of the graph as the best instead of the first one?
Another thing I'd like to be able to do is have the training information nntraintool open in a new window every time I call the train(netA, P, T) function. Right now, every time it's called it just overwrites the previous info in the nntraintool window. Is it even possible to do this?
This is the window I'm talking about:

How to Creat MATLAB GUI for this code?

Hi everyone I wrote this code using MatLab and I need to design a GUI as the following
Draw Button: to draw the path.
Scan Button: If I want to take an image using "Image Acquisition"
Static Text : to show the angels,number of objects and the centers (Individual)
Axes : To show the image after the processing
And is there any reference I should read to help me??
The Code:
im1=imread('C:\Users\Shadow Of Dark\Desktop\sample','jpeg');
im1=rgb2gray(im1);
level=graythresh(im1)
bwfram3=im2bw(im1,level);
bw2=bwareaopen(bwfram3,20);
se=strel('disk',10);
bw2=imclose(bw2,se);
bw2=imcomplement(bw2);
[labeled,numObjects] = bwlabel(bw2,4);
imshow(labeled);
numObjects
info=regionprops(labeled,'all');
centers=cat(2,info.Centroid)
hold on;
angles=zeros(1,numObjects);
j=0;
for i=1:2:2*numObjects-2
l = line([centers(i) centers(i+2)],[centers(i+1) centers(i+3)]);
set(l,'linewidth',3,'color','r');
angles(1,i-j)= atan((centers(i+1) - centers(i+3))/(centers(i) - centers(i+2)))*180/pi;
j=j+1;
end
angles
Firstly, draw in a paper (or Enterprise Architect, ...) what you want and where in the layout. Afterwards, think of the sequence diagram of your process and write it in a paper. Later, divide your code into some functions, related to the steps you have described. Then, create a GUI with the GUI Editor in MATLAB and add a graphical element to your layout. Finally, link each function you have described to your graphical element (read the official help to do it).
(Alternatively, you can do it quicker mixing all these steps, but it is not an appropriate way of doing it).
I find this list to be quite usefull for getting started:
http://www.mathworks.com/matlabcentral/fileexchange/24861-41-complete-gui-examples
You may also want to look at the examples that are already included in matlab.
Go to Start > Matlab > GUIDE

Matlab IMRECT backward compatibility

I've writtend a GUI function in MATLAB R2009b which makes use of the IMRECT function. I need to make sure this GUI also works in MATLAB R2007b: since this release the IMRECT function has undergone extensive changes. I have two question:
1 - in the new (R2009b) IMRECT, a method GETCOLOR is defined which allows to get the color which was selected by the user using the scroll menu. Is there a way to mimic this behavior for the old (R2007b) function?
2 - in MATLAB R2009b I can use WAIT after using IMRECT as follows:
h = imrect(axhandle);
wait(h);
this allows to wait unitl the user as correctly placed his/her rectangle and has double click to confirm the choice. Is there anything analogous that can be used with IMRECT from R2007b?
Unfortunately, you need a workaround for both functions.
Here is one way to do it:
%# Create a figure and some points
fh = figure;plot(rand(10,1),rand(10,1),'.')
ah = gca;
%# this allows the user to place the rectangle. However, the code resumes
%# as soon as the rectangle has been drawn
rh = imrect(ah,[]);
%# Create a dialog to have the possibility to uiwait
wh = warndlg('Please close this dialog once you are done adjusting your rectangle');
uiwait(wh)
%# Get the color of the rectangle
rectKids = get(rh,'Children');
rectangleColor = get(rectKids(1),'Color');
You can use verLessThan to check for the Matlab version in order to get the proper functionality. However, if there are users who'll use the code both on 2007b and 2009b, I suggest you leave the dialog box in for everyone, so that they don't get confused when they switch.