How to create axes in matlab GUIDE - matlab

I want to implement the following code using matlab GUIDE:
axes(handles.axes1);
imshow(image1);
axes(handles.axes2);
imshow(image2);
As I am very new to GUIDE so I am having no idea how to do this. Any guidance.

Open guide selecting empty gui
Drag and drop two axes objects anywhere in the figure.
Right clicking on any axes object and seeing it properties allows to set size, position, and name of the object.
Guide always generate figure file in parallel with .m file containing all callback functions, among them function to be called on opening the gui (just before it is visible) -you can put you imshow() code there...
The whole thing is very intuitive, and has a great help provided by matlab.

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();

how to save figure of gui plot which will run on a computer that does not have matlab

I have made a Gui program that I compile to EXE application which lots csv file into graph data. I buit a save button but I do not know how save figure with different name each time cause (savefig anduisave both uses matlab program). I am posting my code below if anyoff you guys figure out how to save gui figue into image or anything that does require matlab to open. Last function is the callback function for save button.
function ma_Callback(hObject, eventdata, handles)
% i tried uisave but not possible to run computer without matlab cause mcr
% does not run uisave
% i tried copyopbj but since i did not put a name on my figure it did not
% work
%savefig
If you are trying to save a kind of image from your figure, then the best option which supports many aspects, is using print function.
I have already done this in a compiled app and it works perfect. Using print function you can set different file type(vector formats like *.svg are also supported), resolution(dpi), and so many others.
Although you can use print function directly on the figure, but I found that the best way (More Customization like removing or adding some objects and changing many options) is to follow this steps:
Create another figure with Visible='on' but a position that is out of screen with the same width and height of Main Figure.
normalized position = [-1, -1, ?, ?]. (Create this figure in start up and don't destroy it until your app exits, let call it Print Figure).
Copy your figure content (or the parts you are interested in) using copyobj to that figure (you may need to set Parent property of some key objects like panels to this new figure). They would look exactly as they look in the main figure, because they have the same properties. you can add or remove some objects in this step.
Change aspect ratio of "Print Figure" for a better output.
Print this figure with all options (file format, dpi, ...) you need. in my own GUI i allowed the user to change this settings with an input dialog.
In my app i used functions like winopen to show the output, and output directory to the user, when the print task was done. Print process takes some time, specially if dpi is huge, so it is also a good idea to inactivate buttons and show wait cursor.
Update:
a simple usage would be:
print(MainFigure, 'myFileName', '-dpng', '-r300')

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 update plot in one GUI based on activity in second GUI

In one GUI (viewer) I have an image that shows a 2D slice through a 3D image cube. A toolbar button opens a second GUI (z-profile) that plots a 2D graph showing the z-profile of one pixel in the image cube. What I want is to be able to update this plot dynamically when a different pixel is clicked in the original viewer GUI. I've looked in to linkdata but I'm not sure if that can be used to link across two GUIs. Is there a simple way to do this without re-creating the second GUI each time a new pixel is clicked and feeding in the new input location?
You can definitely doing it without recreating the second GUI every time.
Without knowing your specific code I would say that you should store a reference to the second GUI in the first GUI, then in a callback for clicking a pixel in the first GUI, change data in the second GUI via the stored reference (e.g. figure handle). You can store arbitrary data in a figure, for example by using function guidata. A bit of code.
...
figure2 = figure();
figure1 = figure('WindowButtonDownFcn',#myCallback);
guidata(figure1, figure2);
...
function myCallback(obj,eventdata)
figure2 = guidata(obj);
...
Even easier but a bit more error-prone would be to use global variables for storing the references.

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