You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
Question about axes, control group and GUI (GUIDE)
2 views (last 30 days)
Show older comments
Pedro Augusto de Castro e Castro
on 4 Jun 2020
Edited: Pedro Augusto de Castro e Castro
on 10 Jun 2020
Hello,
I have a few questions:
1. I have a GUI with several axes and plots. I would like to make a controul group with radio buttons to control which plots (and axes) are shown. So, I'll have two buttons and half of the axes will be shown at a time. When the user selects the other button, the axes that are displayed will disapear, and the other half will be displayed. When tha user selects another option on the control group, all the info on the axes should disapear, label, title, legend, axis ticks, etc.
2. I also have two buttons, left and right, to control which axes are being shown. This button must consider which set of axes are displayed (defined by the control group). I could make it work considering just one set of axes (ignoring the other half and also the control group).
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/310001/image.png)
3. As you can see in tha figure below, there's two axis ticks being shown. I don't know why that is.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/310004/image.png)
4. To get the selected button I did this:
handles.conv = get(handles.show_conv.SelectedObject,'String');
if strcmp(handles.conv, 'Inversor')
....
elseif strcmp(handles.conv, 'Retificador')
....
end
5. Also, when the simulation (thet will get the variables to plot) is running all the plot appears baing plotted, and when the simulation stops only the one I set to be the top appears. I would like, if possible, to not show the plots when they are being plotted, only when I select them via the left and right button. If I could post a video, this would be easier to understand.
Another thing, what may cause an error that only happens the first time I run the program?
Any ideas?
Thanks!
9 Comments
Tommy
on 4 Jun 2020
What code are you using to hide axes which should be hidden?
You can tell plot() to make an invisible plot, e.g.
p = plot(axes_handle, X, Y, 'Visible', 'off');
Rik
on 4 Jun 2020
You could also actually use your own idea: create two axes and set the Visible property to on or off when appropriate.
Pedro Augusto de Castro e Castro
on 4 Jun 2020
Thanks for your inputs.
I have 30 axes, that I set their visibility accordingly. For exemple:
set(handles.graph_1, 'Visible', 'on'); % 'Perdas nos Transistores, Indutores e Totais - Otimização do Volume'
set(handles.graph_2, 'Visible', 'off'); % 'Volume dos Indutores, Dissipadores e Total - Otimização do Volume'
set(handles.graph_3, 'Visible', 'off'); % 'Peso dos Indutores, Dissipadores e Total - Otimização do Volume'
set(handles.graph_4, 'Visible', 'off'); % 'Perdas nos Transistores, Indutores e Totais - Otimização do Peso'
set(handles.graph_5, 'Visible', 'off'); % 'Volume dos Indutores, Dissipadores e Total - Otimização do Peso'
set(handles.graph_6, 'Visible', 'off'); % 'Peso dos Indutores, Dissipadores e Total - Otimização do Peso'
set(handles.graph_7, 'Visible', 'off'); % 'Perdas nos Transistores, Indutores e Totais - Otimização das Perdas'
set(handles.graph_8, 'Visible', 'off'); % 'Volume dos Indutores, Dissipadores e Total - Otimização das Perdas'
set(handles.graph_9, 'Visible', 'off'); % 'Peso dos Indutores, Dissipadores e Total - Otimização das Perdas'
set(handles.graph_10, 'Visible', 'off'); % 'Rendimento x Densidade de Potência Volumétrica - Otimização do Volume e Diferentes Ripples'
set(handles.graph_11, 'Visible', 'off'); % 'Rendimento x Densidade de Potência Mássica - Otimização do Volume e Diferentes Ripples'
set(handles.graph_12, 'Visible', 'off'); % 'Rendimento x Densidade de Potência Volumétrica - Otimização do Peso e Diferentes Ripples'
set(handles.graph_13, 'Visible', 'off'); % 'Rendimento x Densidade de Potência Mássica - Otimização do Peso e Diferentes Ripples'
set(handles.graph_14, 'Visible', 'off'); % 'Rendimento x Densidade de Potência Volumétrica - Otimização das Perdas e Diferentes Ripples'
set(handles.graph_15, 'Visible', 'off'); % 'Rendimento x Densidade de Potência Mássica - Otimização das Perdas e Diferentes Ripples'
Rik
on 4 Jun 2020
That looks difficult to handle. Do you have a reason for not putting those axes (or line?) handles in an array?
Tommy
on 4 Jun 2020
Note that plotting on a set of axes may reset all axes properties except for units and position (meaning, invisible axes will be made visible) depending on the value of the NextPlot property. You can use hold on to avoid this. But as far as I can tell, a plot will show even on invisible axes unless you make the plot invisible also:
ax = axes('Visible', 'off');
hold(ax, 'on') % so axes remain invisible after plotting
plot(ax, 1:10) % plot still shows
Rik
on 4 Jun 2020
You can put all handles that should be set to Visible in an array together. The set function will accept arrays of handles to mixed types, as long as all the properties you're trying to set exist in each object.
Pedro Augusto de Castro e Castro
on 4 Jun 2020
When I plot in one of the axes I do something like this:
axes(handles.graph_12);
cla reset; % Do a complete and total reset of the axes.
if ~isempty(handles.graph_12)
hold(handles.graph_12,'on');
for k = 1 : length(delta_i_inv)
txt = num2str(delta_i_inv(k));
scatter(handles.graph_12, [handles.PesoResults_inv(k).Ripple.DensidadePotenciaVol], [handles.PesoResults_inv(k).Ripple.Rendimento], 'DisplayName',txt,'Tag',"Ripple: " +delta_i_inv(k)*100+ " [%]");
end
legend(handles.graph_12);
xlabel(handles.graph_12, 'Densidade de Potência [kW/dm³]');
ylabel(handles.graph_12, 'Rendimento');
title(handles.graph_12, 'Rendimento x Densidade de Potência Volumétrica do Inversor - Otimização do Peso e Diferentes Ripples');
handles.graph_12.Tag = 'ParetoV_Peso_Inv';
end
Do you mean doing something like this?
handles.allAxes = [handles.graph_1, handles.graph_2, handles.graph_3, handles.graph_4, handles.graph_5, handles.graph_6, handles.graph_7, handles.graph_8, handles.graph_9, handles.graph_10, handles.graph_11, handles.graph_12, handles.graph_13, handles.graph_14, handles.graph_15];
Rik
on 9 Jun 2020
Since it is not clear what exactly your edit of your question is: could you summarize the edit? What is the main remaining issue?
Pedro Augusto de Castro e Castro
on 10 Jun 2020
Edited: Pedro Augusto de Castro e Castro
on 10 Jun 2020
I solved some of those problems. Right now what I can't understand is: I have two sets of 15 axes each. I have a ButtonDownFcn for all of them, so when I click on one of the plots, a custom data tip will show up. In the first set, everything is fine, I can click on whichever axes that it'll work. However, for the second set, only the last axes works (axes 30). The others I can't even click on them.
I coppied the code for the first set to the second, and changed some variables. Do you have any idea of what might be happening?
EDIT: To exemply, I'll plot the code for two axes (axes 30 and 29). The first one works fine, but the second doesn't
Plotting:
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Axes 30 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
axes(handles.graph_30);
% cla reset; % Do a complete and total reset of the axes.
% axes('Visible', 'off');
% set(gca,'XTick',[], 'YTick', [])
if ~isempty(handles.graph_30)
hold(handles.graph_30,'on');
min_axis_x = 10000;
min_axis_y = 10000;
max_axis_x = 0;
max_axis_y = 0;
for k = 1 : length(delta_i_ret)
txt = num2str(delta_i_ret(k));
scatter(handles.graph_30, [handles.PerdasResults_ret(k).Ripple.DensidadePotenciaPeso], [handles.PerdasResults_ret(k).Ripple.Rendimento], 'DisplayName',txt,'Tag',"Ripple: " +delta_i_ret(k)*100+ " [%]");
min_axis_x_aux = min([handles.PerdasResults_ret(k).Ripple.DensidadePotenciaPeso])
min_axis_x = min(min_axis_x, min_axis_x_aux)
min_axis_y_aux = min([handles.PerdasResults_ret(k).Ripple.Rendimento])
min_axis_y = min(min_axis_y, min_axis_y_aux)
max_axis_x_aux = max([handles.PerdasResults_ret(k).Ripple.DensidadePotenciaPeso])
max_axis_x = max(max_axis_x, max_axis_x_aux)
max_axis_y_aux = max([handles.PerdasResults_ret(k).Ripple.Rendimento])
max_axis_y = max(max_axis_y, max_axis_y_aux)
end
legend(handles.graph_30);
axis([min_axis_x max_axis_x min_axis_y max_axis_y])
xticks([min_axis_x:(max_axis_x - min_axis_x) / 10 :max_axis_x]);
yticks([min_axis_y:(max_axis_y - min_axis_y) / 10 :max_axis_y]);
xlabel(handles.graph_30, 'Densidade de Potência [kW/kg]');
ylabel(handles.graph_30, 'Rendimento');
title(handles.graph_30, 'Rendimento x Densidade de Potência Mássica do Retificador - Otimização das Perdas e Diferentes Ripples');
handles.graph_30.Tag = 'ParetoM_Perdas_Ret';
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Axes 30 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Axes 29 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
axes(handles.graph_29);
% cla reset; % Do a complete and total reset of the axes.
% set(gca,'XTick',[], 'YTick', [])
% axes('Visible', 'off');
if ~isempty(handles.graph_29)
hold(handles.graph_29,'on');
min_axis_x = 10000;
min_axis_y = 10000;
max_axis_x = 0;
max_axis_y = 0;
for k = 1 : length(delta_i_ret)
txt = num2str(delta_i_ret(k));
scatter(handles.graph_29, [handles.PerdasResults_ret(k).Ripple.DensidadePotenciaVol], [handles.PerdasResults_ret(k).Ripple.Rendimento], 'DisplayName',txt,'Tag',"Ripple: " +delta_i_ret(k)*100+ " [%]");
min_axis_x_aux = min([handles.PerdasResults_ret(k).Ripple.DensidadePotenciaVol])
min_axis_x = min(min_axis_x, min_axis_x_aux)
min_axis_y_aux = min([handles.PerdasResults_ret(k).Ripple.Rendimento])
min_axis_y = min(min_axis_y, min_axis_y_aux)
max_axis_x_aux = max([handles.PerdasResults_ret(k).Ripple.DensidadePotenciaVol])
max_axis_x = max(max_axis_x, max_axis_x_aux)
max_axis_y_aux = max([handles.PerdasResults_ret(k).Ripple.Rendimento])
max_axis_y = max(max_axis_y, max_axis_y_aux)
end
legend(handles.graph_29);
axis([min_axis_x max_axis_x min_axis_y max_axis_y])
xticks([min_axis_x:(max_axis_x - min_axis_x) / 10 :max_axis_x]);
yticks([min_axis_y:(max_axis_y - min_axis_y) / 10 :max_axis_y]);
xlabel(handles.graph_29, 'Densidade de Potência [kW/dm³]');
ylabel(handles.graph_29, 'Rendimento');
title(handles.graph_29, 'Rendimento x Densidade de Potência Volumétrica do Retificador - Otimização das Perdas e Diferentes Ripples');
handles.graph_29.Tag = 'ParetoV_Perdas_Ret';
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Axes 29 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Calling the update function:
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Axes 30 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% --- Executes on mouse press over axes background.
function graph_30_ButtonDownFcn(hObject, eventdata, handles) % 'Rendimento x Densidade de Potência Mássica - Otimização das Perdas e Diferentes Ripples'
% hObject handle to graph_15 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
datacursormode(handles.figMainWindow, 'on') %on
handles.dcm = datacursormode(handles.figMainWindow);
set(handles.dcm,'UpdateFcn',@(t,e) myupdatefcn(t,e, handles.PerdasResults_ret, hObject));
% set(handles.dcm,'UpdateFcn',@(t,e) myupdatefcn(t,e, handles.PerdasResults_ret));
% set(handles.dcm,'UpdateFcn',@(t,e) myupdatefcn(t,e, handles.PerdasResults_inv, hObject));
% handles.currentPoint = get(hObject,'CurrentPoint');
% handles.axesForCurrentPoint = hObject;
guidata(hObject, handles);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Axes 30 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Axes 29 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% --- Executes on mouse press over axes background.
function graph_29_ButtonDownFcn(hObject, eventdata, handles) % 'Rendimento x Densidade de Potência Volumétrica - Otimização das Perdas e Diferentes Ripples'
% hObject handle to graph_14 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
datacursormode(handles.figMainWindow, 'on') %on
handles.dcm = datacursormode(handles.figMainWindow);
set(handles.dcm,'UpdateFcn',@(t,e) myupdatefcn(t,e, handles.PerdasResults_ret, hObject));
% set(handles.dcm,'UpdateFcn',@(t,e) myupdatefcn(t,e, handles.PerdasResults_ret));
guidata(hObject, handles);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Axes 29 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
The update function:
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Axes 30 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
case 'ParetoM_Perdas_Ret'
handles = guidata(hObject);
d = pdist2([event.Target.XData(:), event.Target.YData(:)], event.Position);
[~, minIdx] = min(d);
% assignin('base','d',d)
% assignin('base','minIdx',minIdx)
DispName = str2double(event.Target.DisplayName)
% assignin('base','DispName',DispName)
index_graph = find(deltaI == DispName);
% assignin('base','index',index)
% assignin('base','minIdx',minIdx)
% pos = get(event,'Position');
dts = get(event.Target,'Tag');
% assignin('base','dts',dts)
% [~,j]= find( xdata==pos(1) & ydata==pos(2) );
handles.currentPoint = [(event.Target.XData(minIdx)) (event.Target.YData(minIdx))];
handles.currentPointFsw = info(index_graph).Ripple(minIdx).Fsw;
handles.currentPointDeltaI = DispName;
handles.currentPointResults= info;
handles.currentPointInfo = 'M_Perdas';
guidata(hObject, handles);
txt = {dts + " - Retificador",...
['Densidade de Potência: ', num2str(event.Target.XData(minIdx)), ' [kW/kg]'],...
['Rendimento: ', num2str(100 * event.Target.YData(minIdx)), ' [%]'],...
['Frequência de Chaveamento: ', num2str(info(index_graph).Ripple(minIdx).Fsw), ' [Hz]' ],...
['Material do Indutor: ', info(index_graph).Ripple(minIdx).Material]...
['Dissipador: ', info(index_graph).Ripple(minIdx).PartNumberHS]...
['Comprimento do Dissipador: ', num2str(info(index_graph).Ripple(minIdx).CompHS), ' [dm]']...
['Configuração: ', info(index_graph).Ripple(minIdx).ConfigHS]};
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Axes 30 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Axes 29 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
case 'ParetoV_Perdas_Ret'
d = pdist2([event.Target.XData(:), event.Target.YData(:)], event.Position);
[~, minIdx] = min(d);
DispName = str2double(event.Target.DisplayName);
% assignin('base','DispName',DispName)
index_graph = find(deltaI == DispName);
% assignin('base','index',index)
% assignin('base','minIdx',minIdx)
% pos = get(event,'Position');
dts = get(event.Target,'Tag');
% assignin('base','dts',dts)
handles.currentPoint = [(event.Target.XData(minIdx)) (event.Target.YData(minIdx))];
handles.currentPointFsw = info(index_graph).Ripple(minIdx).Fsw;
handles.currentPointDeltaI = DispName;
handles.currentPointResults= info;
handles.currentPointInfo = 'V_Perdas';
guidata(hObject, handles);
% [~,j]= find( xdata==pos(1) & ydata==pos(2) );
txt = {dts + " - Retificador",...
['Densidade de Potência: ', num2str(event.Target.XData(minIdx)), ' [kW/dm³]'],...
['Rendimento: ', num2str(100 * event.Target.YData(minIdx)), ' [%]'],...
['Frequência de Chaveamento: ', num2str(info(index_graph).Ripple(minIdx).Fsw), ' [Hz]' ],...
['Material do Indutor: ', info(index_graph).Ripple(minIdx).Material]...
['Dissipador: ', info(index_graph).Ripple(minIdx).PartNumberHS]...
['Comprimento do Dissipador: ', num2str(info(index_graph).Ripple(minIdx).CompHS), ' [dm]']...
['Configuração: ', info(index_graph).Ripple(minIdx).ConfigHS]};
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Axes 29 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Thanks in advance
Answers (0)
See Also
Categories
Find more on Graphics Performance in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)