Info
La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.
Need to convert 2012b UI calls to 2018b UI Calls
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
The following code works as desired under MATLAB R2012b and is being converted to work under R2018b.
The code sets up two main tabs and a data panel. The first tab has two sub-tabs which, under R2012b, populate the data panel with:
"1, 2, 3, ... 15" (sub-tab 1 of main tab 1)
"2, 4, 6, ... 30" (sub-tab 2 of main tab 1)
This is seen by using the debugger to step through code lines 33 & 34. Once the main function completes the data panel is cycled so that the data associated with sub-tab 1 of main tab 1 is displayed; specifically: "1, 2, 3, ... 15".
Under MATLAB R2018b stepping through lines 33 & 34 gives the same results to that point. Once the main function ends the data panel is left displaying "2, 4, 6, ... 30".
If lines 29 and 30 are enabled the data panel is cleared, a second problem.
Code follows:
function PanelExample
% Initialize data
data = 1:15;
% Initialize GUI figure
fig = figure('Units', 'norm', 'Position', [0 0.2 0.5 0.5]);
% Tab Group setup and a data panel that is an edit area
hMainTabGroup = uitabgroup('TabLocation', 'left');
dataPanel = uipanel('Parent', fig, 'Position', [0.04 0.04 0.95 0.95], 'tag', 'mainDisplay');
% First tab group, default
tab1 = uitab('Parent', hMainTabGroup, 'Title', 'Tab1', 'tag', 'tab1');
panel1 = uipanel('Parent', dataPanel, 'Position', [0 0 1 1], 'tag', 'panel1');
% Tab Group 1
nMainTabs = 1;
hSubTabGroups(nMainTabs) = uitabgroup('Parent', tab1, 'TabLocation', 'bottom');
set(hSubTabGroups(nMainTabs), 'SelectionChangedFcn', {@tab1SelectionChange_callback, panel1});
% Sub tabs of tab1
tab1_Data = uitab('Parent', hSubTabGroups(nMainTabs), 'Title', 'Data', 'tag', 'tab1_Data');
tab1_2xData = uitab('Parent', hSubTabGroups(nMainTabs), 'Title', '2xData', 'tag', 'tab1_2xData');
% Tab Group 2
nMainTabs = nMainTabs + 1;
tab2 = uitab('Parent', hMainTabGroup, 'Title', 'Tab2');
hSubTabGroups(nMainTabs) = uitabgroup('Parent', tab2, 'TabLocation', 'bottom');
% panel2 = uipanel('Parent', dataPanel, 'Position', [0 0 1 1], 'tag', 'panel2'); % Only make things worse, comment
% set(hSubTabGroups(nMainTabs), 'SelectionChangedFcn', {@tab2SelectionChange_callback, panel2}); % Only make things worse, comment
% Populate Tab1 sub-tabs
drawtab1_Data(panel1, data)
drawtab2_Data(panel1, data)
% *** EVERYTHING WORKS AS EXPECTED TO HERE AS LONG AS LINES 29 & 30 ARE COMMENTED *** %
% *** LINES 29 & 30 RESULT IN A CLEARED OUT DATA PANEL *** %
% Sub tab of tab2
tab2_Data = uitab('Parent', hSubTabGroups(nMainTabs), 'Title', 'Data', 'tag', 'tab2_Data');
% Set tab select call backs
set(hSubTabGroups, 'SelectionChangedFcn', {@mainSelectionChange_callback, hSubTabGroups, dataPanel});
% Cycle through tabs to sync data on tabs
set(hMainTabGroup, 'SelectedTab', tab2);
set(hMainTabGroup, 'SelectedTab', tab1);
set(hSubTabGroups(1), 'SelectedTab', tab1_2xData);
set(hSubTabGroups(1), 'SelectedTab', tab1_Data);
% No preset data for Tab2 Data
set(hMainTabGroup, 'SelectedTab', tab2);
set(hSubTabGroups(nMainTabs), 'SelectedTab', tab2_Data);
set(hMainTabGroup, 'SelectedTab', tab1);
% ......
end
function drawtab1_Data(tab1_Data, data)
txtBox = uicontrol(tab1_Data, 'Style', 'edit', 'HorizontalAlignment', 'left', 'Units', 'norm');
set(txtBox, 'Position', [0 0 1 1]);
set(txtBox, 'FontName', 'Courier', 'FontSize', 10);
txtStr = num2str(data(1));
for i = 2:numel(data)-1
txtStr = sprintf('%s, %d', txtStr, data(i));
end
txtStr = [txtStr ', ' num2str(data(end))];
set(txtBox, 'Max', length(txtStr));
set(txtBox, 'String', txtStr);
end
function drawtab2_Data(tab1_2xData, data)
txtBox = uicontrol(tab1_2xData, 'Style', 'edit', 'HorizontalAlignment', 'left', 'Units', 'norm');
set(txtBox, 'Position', [0 0 1 1]);
set(txtBox, 'FontName', 'Courier', 'FontSize', 10);
txtStr = num2str(2*data(1));
for i = 2:numel(data)-1
txtStr = sprintf('%s, %d', txtStr, 2*data(i));
end
txtStr = [txtStr ', ' num2str(2*data(end))];
set(txtBox, 'Max', length(txtStr));
set(txtBox, 'String', txtStr);
end
function tab1SelectionChange_callback(hObject, eventData, data)
tabSelected = get(eventData.NewValue, 'title');
% ....
end
0 comentarios
Respuestas (0)
La pregunta está cerrada.
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!