How can I add waitbar in the current GUI window MATLAB? - matlab

I am having a GUI figure, which contains some buttons, I want to show waitbar on the same GUI window on which buttons are placed, I tried different solutions but in vain. e.g when user clicks on button it starts showing me waitbar on left bottom side of the figure.

You could try to add a java waitbar in your figure.
Put this in the OpeningFcn
PB=javaObjectEDT(javax.swing.JProgressBar);
javacomponent(PB,[10,10,200,20],gcf); %put at bottom part of the current figure
set(handles.output.Children(1),'Tag','first_bar'); %make sure you can find it back
In the callback of any function you can then set the bar to a value between 0 and 100 using this code:
h=findobj(handles.output.Children,'Tag','first_bar');
set(h.JavaPeer,'Value',rand(1)*100)
You can make it visible or invisible just as you would any GUI object in Matlab using
h=findobj(handles.output.Children,'Tag','first_bar');
set(h,'visible','off');
Here you can find details about the JProgressBar . For example using this you get a string with the progress inside the bar.
h=findobj(handles.output.Children,'Tag','first_bar');
set(h.JavaPeer,'StringPainted',1)

Related

Matlab /Wait bar/ Progress bar/GUI

I'm trying to use the wait bar in a gui for a matlab program that recognises images. In simple words, a bounding box(rectangle) appears when there is a irregularity.
The bounding box doesnt appear when I have the waitbar as normal or modal:
f = waitbar(0,'Please wait...','WindowStyle','normal');
But the bounding box appears when I use the following command
f = waitbar(0,'Please wait...','WindowStyle','docked');
I would want the wait bar to pop and not be docked. Any suggestions?
Recommendations?
Thanks
#ssroy, The bounding box(rectangle) is probably added to the figure of the waitbar instead of the figure where you want it. I would try to recall focus to that figure (or your GUI) when adding the bounding box, and follow it by refocussing on the waitbar afterwards.
In order to refocus on the waitbar , you can use again f = waitbar(0,'Please wait...','WindowStyle','normal'); even if you don't change anything on it

how to manage uipanels matlab gui

I have 6 uipanels ,all same size overlapped one over another. I have to add buttons edit text to all the uipanels.but I can edit only 6th uipanel and all others are hidden.how can I make only one uipanel visible at a time so that I can easily add buttons and text to it. I have to add a push button in each panel which when clicked should show succeeding uipanel and hide previous uipanel.
For example,
I have a uipanel1 with a push button.when. I click the push button,it should show uipanel2 and hide uipanel1.
thanks
First of all you have to define yours uipanels as variables. For example, uipanel1 = uipanel(...); uipanel2 = uipanel(...)
So you can access easily to your six uipanel handles and put these handles in your button callback function.
Another solution would be to use the 'Tag' property for the uipanel in order to identify the uipanel. It may be longer but by using the findobj('Tag','uipanel1_tag') function, you can easily find the desired handle.

MATLAB GUI tab ordering

In my current project I have a bunch of edit text boxes in my gui. When I/m in the first text blank and hit the tab key it skips to the third text box, when I hit tab again it goes to the second box. Every time I hit tab it jumps around in this weird order. I found out that the order is dependent on the order of the callback function for each text box. Without going in an copy pasting and changing around the code that gets generated by guide is there a better way to order my text boxes.
So for example when I'm in the box red x and hit tab it takes me to the box red z, than red y than green x then green z. I want to be able to click red x and then using just tab step through and fill out the other blocks. Is it at all possible to re-order?
GUIDE-generated GUI
When using GUIDE, you can simply use the "Tab Order Editor". Get to it using the following menu item:
For this simple GUI, with a single button and two text boxes, you would see the following dialog box:
Then set the tab order by moving UI objects up/down.
Programmatic GUI
To set the tab order programatically, you can use uistack to reorder the handles.
For example, to move a uicontrol "up" one in the order:
uistack(hui,'up',1)
To see the order of the handles to all controls in figure hf:
ch = get(hf,'Children')

turn on colorbar programmatically in clustergram

I know that one can insert a colorbar by clicking the colorbar icon in the clustergram GUI. Is there a way to do it programmatically?
I tried
cgo = clustergram(data)
colorbar;
This makes a colorbar in a new figure window. How can a colorbar be created with proper positioning in a clustergram figure as if the button was clicked?
There is a function buried away (HeatMap.plot>showColorbar) that neatly positions the colorbar to the left of both the heat map and the dendogram (the lines). Just running colorbar(...) will mess up the relative positioning of the dendogram and the heatmap. So you need to somehow run the callback or carefully duplicate all of the position computations. It's easier to just run the callback. Here's how.
To create the colorbar programmatically for a clustergram, and keep the color bar button in sync, you need to use the button's assigned callback and set the button's state.
Create the clustergram:
load filteredyeastdata
cgo = clustergram(yeastvalues(1:30,:),'Standardize','Row');
Get the handle for color bar button:
cbButton = findall(gcf,'tag','HMInsertColorbar');
Get callback (ClickedCallback) for the button:
ccb = get(cbButton,'ClickedCallback')
ccb =
#insertColorbarCB
[1x1 clustergram]
That gives us a handle to the function assigned by the callback (#insertColorbarCB), and the function's third input argument (the clustergram object). The button's handle and an empty event object are implicitly the first two arguments.
Change the button state to 'on' (clicked down):
set(cbButton,'State','on')
Run the callback to create the colorbar:
ccb{1}(cbButton,[],ccb{2})
Note that the button State must be changed to 'on' first, otherwise the callback won't do anything.
I just managed to solve this problem.
What I did:
I added this function to the clustergram code (I put it at line 1486)
%%%%%%%%%%%%%%
function insertColorbarCBALWAYS(obj)
hFig= gcbf;
obj.Colorbar = true;
end
%%%%%%%%%%%%%%%
and then at line 415 of the clustergram.m file I added this line of code
insertColorbarCBALWAYS(obj);
to call the above function. Save and go: now the colorbar will always be there, once the clustergram is drawn.
Previous method was not working for me so I made this workaround.
One may even save the new clustergram code as clustergramCM such that you can draw cgram in both ways.

Publishing .fig files without having them appear on screen

I have some code that generates a number of MATLAB figures. At the end of my program I want to publish these figures in a report. I have a script, which is passed to publish(), that uses openfig() to include the figures in the document.
This causes these figures to flash up on the screen. This is particularly annoying when I am opening figures inside a loop using a combination of close and snapnow. I've tried making these figures invisible using
openfig(PathToFigure, 'new', 'invisible')
This stops the image appearing on the screen but also stops it appearing in the report.
Is there a way of including .fig files in the report without having them appear on screen?
Open the figure with f=openfig(PathToFigure, 'new', 'invisible'). Then move the figure off-screen by setting its Position property (perhaps to something with negative values for the left and bottom pixels), set its Visible property to on, call snapnow. Delete the figure.
I would actually recommend setting their visibility to 'off' when you create those figures with
f = figure('Visible','off');