I made a GUI with two uipanels, each containing 4 image axes.
I plotted different figures on each panel and want to switch between panels by a push button.
For this I used the following:
Initially, I set uipanel2 to 'visible' 'on' and uipanel3 to 'visible' 'off';
Then when I push 'push button' it checks if uipanel is 'on' and turns on and off respectively.
% Code:
set(handles.uipanel2,'visible','on');
set(handles.uipanel3,'visible','off');
% When I push 'push button':
if strcmp(get(handles.uipanel2,'visible'),'on')
disp('panel-2 onn switching it off')
set(handles.uipanel2,'visible','off');
set(handles.uipanel3,'visible','on');
elseif strcmp(get(handles.uipanel3,'visible'),'on')
disp('panel-3 onn switching it off')
set(handles.uipanel3,'visible','off');
set(handles.uipanel2,'visible','on');
end
It doesn't work as expected I don't see panels switching.
For displaying images I used code like this:
% Panel-2
axes(handles.RCC);
imshow(img_RCC,lims);
axes(handles.LCC);
imshow(img_LCC,lims);
axes(handles.RML);
imshow(img_RML,lims);
axes(handles.LML);
imshow(img_LML,lims);
% Panel-3
axes(handles.RCC_Orig);
imshow(img_RCC,lims);
axes(handles.LCC_Orig);
imshow(img_LCC,lims);
axes(handles.RML_Orig);
imshow(img_RML,lims);
axes(handles.LML_Orig);
imshow(img_LML,lims);
Update: I can only see the GUI panel on top being 'not visible' and switching to 'visible'. The panel on bottom I think is still there but I don't know how to make it come on top
Related
I'm writing an application in MATLAB and want to update the look of it. is it possible to change the icons of the buttons in the toolbar in MATLAB code?
The code will be compiled and I am not using GUIDE; ideally there's a way to get the button handles and set each icon individually although I don't know how I would do this.
But with higher quality icons.
Yes, you can change the figure toolbar icons, or add your own.
I've detailed how to change the icon below, as well as other useful things to do with the toolbar whilst you're editing the properties anyway.
See the code comments for details.
Get the toolbar object
% Initialise some figure
fig = figure( 'Name', 'MyApp', 'NumberTitle', 'off' )
% Get the figure toolbar handle
tbar = findall( fig, 'tag', 'FigureToolBar' );
You can do findall(tbar) at this point to list the names of all the buttons
Hiding buttons
Let's say you want to hide the "new figure" button:
% Get the button from the tbar object
btn = findall( tbar, 'tag', 'Standard.NewFigure' )
% Set to not visible
set( btn, 'Visible', 'off' );
Changing callbacks
Let's say you want the print button to trigger a print-preview callback instead of printing directly (you could assign any custom callback function to any button):
% Get the button again
btn = findall( tbar, 'tag', 'Standard.PrintFigure' );
% Change the callback (and the tooltip to match)
set( btn, 'ClickedCallback', 'printpreview(gcbf)', ...
'TooltipString', 'Print preview' );
Changing the icon
At this point you can see all button attributes are editable, including the image as per your original question.
In particular, just change the CData property:
% Update the print button to have a print preview icon
% This should be a 16*16 RBG image matrix, use imread to get from file
img = imread( 'printpreview.bmp' )
% Assign CData property to button already acquired
set( btn, 'CData', img );
Output (I used a random print preview icon, seen 4th from the left):
Add new buttons
You can add new buttons by simply creating uipushtool objects (with CData property set for the icon image) with the tbar object as a parent.
Change the separators
The vertical grey separators can be added or removed (useful for creating your own button groups or when removing buttons). Simply set the 'Separator' property to 'off' or 'on', for a separator on the left side of a button.
For a compiled app, this may be against The MathWorks T&Cs, but this is the how to not the should you do this!
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)
I have a Matlab GUIDE figure with nested panels. I also have control objects on top of the panels. Here's a notional example:
In order to align all of the checkboxes, they all need to be in the same control group. I want to move the checkboxes so that their parent is the main panel rather than one of the sub-panels. The sub-panels are just there for visual grouping and don't really have a functional value.
The object browser shows the relationships, but I see no way to change it. I've tried pasting the objects I want to move outside the sub-panel and dragging them back in, but they automatically get added to the sub-panel. If I paste outside of the sub-panel I can use the arrow keys to move them back in and the parent will stay the main panel, but that gets to be tedious.
How can I change the parent panel of a GUIDE control object?
Building the GUI with guide a possible solution could be:
add the main uipanel
add all the checkbox in the main `uipanel'
align them (e. g. by selecting some of them and then use the Align Objects tool on the guide toolbar
add the secondary uipanel over some of the checkbox. It will cover the `checkbox'
select the secondary uipanel
right-click on the mouse to pop-up the context menu
select the Send to Back option
If you want to create the GUI "programmatically" you can:
create a figure
add the main panel with uipanel
add the checkboxes with uicontrol setting the Style property to checkbox and the position property so that they will be placed in the main panel
add the secondary uipanel. Also in this case the secondary uipanel will mask the checkbox
push the secondary panel back using the uistack function
Thsi is a possible implementation
% Create the figure
figure
% Add the Main uipanel
p1=uipanel('units','normalized','position',[.1 .1 .5 .7],'title','Main Panel')
% Add come checkboxes
cb1=uicontrol('parent',p1,'style','checkbox','units','normalized', ...
'position',[.1 .7 .3 .1],'string','checkbox 1')
cb2=uicontrol('parent',p1,'style','checkbox','units','normalized', ...
'position',[.1 .6 .3 .1],'string','checkbox 2')
cb3=uicontrol('parent',p1,'style','checkbox','units','normalized', ...
'position',[.1 .5 .3 .1],'string','checkbox 3')
% Add the Secondary uipanel
p2=uipanel('parent',p1,'units','normalized','position',[.05 .4 .4 .5], ...
'title','Secondary Panel')
% Push the secondary uipanel back
uistack(p2,'bottom')
Hope this helps.
Qapla'
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.
This is the bar graph that I want to display on the GUIDE GUI. I put this code into the OpeningFcn function of the GUIDE GUI, and what essentially happens is that the actual box section dedicated to the graph (its tagged "axes1") appears in the GUI window, but then another Figure window appears displaying the bar graph. How would I go about placing this bar graph into the GUIDE GUI in the space dedicated to the box axes1?
I do not need any push button trigger to display it. The graph should appear in its dedicated spot on the GUIDE GUI when the GUI window is open.
EDIT: This is the graph data I want to display. I was using the previous one as an example so I could learn from it. However, for some reason there is a problem of the below graph appearing twice in the window - it appears once, closes, and then appears again. How would I fix it so it only appears once? All of this is under OpeningFcn and I don't have additional code under CreateFcn.
dbedit = matfile('varDatabase.mat', 'Writable', true);
results_pData = dbedit.pData;
results_uData = dbedit.uData;
results_name = dbedit.name;
% Create data for each set of bars for data from each group
% i.e. [participant, population].
% Population is defined as the previous user data stored in its full in uData.
expSingle = [((results_pData(1,2)/7)*100), ((mean(results_uData(:,2))/7)*100)];
expConjugate = [((results_pData(1,3)/7)*100), ((mean(results_uData(:,3))/7)*100)];
ctlSingle = [((results_pData(1,4)/7)*100), ((mean(results_uData(:,4))/7)*100)];
ctlConjugate = [((results_pData(1,5)/7)*100), ((mean(results_uData(:,5))/7)*100)];
% Create a vertical bar chart using the bar function
bar(handles.axes1,1:2, [expSingle' expConjugate' ctlSingle' ctlConjugate'], 1)
% Set the axis limits
axis([0 2.8 0 100])
set(gca,'XTickLabel',{results_name,'Population'})
% Add title and axis labels
title('Proportion of Responses for Conjunctive vs. Single Choices')
xlabel('Entity')
ylabel('Proportion of Responses (%)')
% Add a legend
legend('Single Choice, Experimental', 'Conjugative Choice, Experimental',...
'Single Choice, Control', 'Conjugative Choice, Control')
Input would be greatly appreciated.
That's because of your call to figure right after the creation of your data, which indeed creates a new figure outside of your GUI.
To solve your problem remove that line, and consider adding the actual axes handles in the call to bar:
bar(handles.axes1,1:12, [measles' mumps' chickenPox'], 1)
Therefore your whole code could look like this:
%Create data for childhood disease cases
measles = [38556 24472 14556 18060 19549 8122 28541 7880 3283 4135 7953 1884];
mumps = [20178 23536 34561 37395 36072 32237 18597 9408 6005 6268 8963 13882];
chickenPox = [37140 32169 37533 39103 33244 23269 16737 5411 3435 6052 12825 23332];
%Create a vertical bar chart using the bar function
%// Remove the call to figure.
bar(handles.axes1,1:12, [measles' mumps' chickenPox'], 1)
% Set the axis limits
axis([0 13 0 40000])
set(gca, 'XTick', 1:12)
% Add title and axis labels
title('Childhood diseases by month')
xlabel('Month')
ylabel('Cases (in thousands)')
% Add a legend
legend('Measles', 'Mumps', 'Chicken pox')
That should work now