📄 test_editmultiueparameter.m
字号:
Position = [(FenceButtonPosition(1) + TabSpace * 2 + Part1Wdith), ...
(EditFrame2Position(2) + 6 + (FenceNumber1 - num)*FenceButtonHeight), ...
Part2Wdith, (TextHeight - 0)] ;
EditHandle1 = com_Uicontrol( FigureHandle , Position, 'edit', RefScreenSize ) ;
set(EditHandle1, 'Tag', ['UENumberPercentEdit', TagIndex(num)], 'FontSize', 8, ...
'Callback', ['link_EditMultiUEParameter(''EditUENumberPercent_Callback'',gcbo)'] ) ;
% save the handles of Percent .
UENumberPercentHandles = [UENumberPercentHandles EditHandle1] ;
% generate the edit to Number .
Position = [(FenceButtonPosition(1) + TabSpace*3 + Part1Wdith + Part2Wdith ), ...
(EditFrame2Position(2) + 6 + (FenceNumber1 - num)*FenceButtonHeight), ...
Part3Wdith, (TextHeight - 0)] ;
EditHandle2 = com_Uicontrol( FigureHandle , Position, 'edit', RefScreenSize ) ;
set(EditHandle2, 'Tag', ['ThroughputPercentEdit', TagIndex(num)], 'FontSize', 8 , ...
'Callback', ['link_EditMultiUEParameter(''EditThroughputPercent_Callback'',gcbo)'] ) ;
% save the handles of Number .
ThroughputPercentHandles = [ThroughputPercentHandles EditHandle2] ;
% generate the edit to Number .
Position = [(FenceButtonPosition(1) + TabSpace * 4 + Part1Wdith + Part2Wdith * 2 + TabSpace ), ...
(EditFrame2Position(2) + 6 + (FenceNumber1 - num)*FenceButtonHeight), ...
(Part4Wdith - TabSpace * 2), (TextHeight - 0)] ;
EditHandle2 = com_Uicontrol( FigureHandle , Position, 'pushbutton', RefScreenSize ) ;
set(EditHandle2, 'Tag', ['UEParameterButton', TagIndex(num)], 'FontSize', 8 , ...
'String', ButtonString, 'Enable', 'off', ...
'Callback', ['link_EditMultiUEParameter(''EditUEParameter_Callback'',gcbo)'] ) ;
end
% save the all kinds of handles.
setappdata( FigureHandle, 'UENumberPercentHandles', UENumberPercentHandles ) ;
setappdata( FigureHandle, 'ThroughputPercentHandles', ThroughputPercentHandles ) ;
% bottom pushbuttons .
% -------------------------------------------------------------
SoftLanguage = 'Chinese' ;
if strcmp( SoftLanguage, 'English' )
ButtonString = {'Cancel'; 'OK'} ;
elseif strcmp( SoftLanguage, 'Chinese' )
ButtonString = {'取消 '; '确认'} ;
else
return ;
end
ButtonWidth = 70 ;
ButtonXPos = FigureWidth - ButtonWidth - TabSpace * 2 ;
ButtonYPos = TabSpace * 1.3 ;
ButtonHeight = 20 ;
ButtonPosition = [ButtonXPos ButtonYPos ButtonWidth TextHeight] ;
% generate the pushbutton: Cancel .
ButtonHandle = com_Uicontrol( FigureHandle, ButtonPosition, 'Pushbutton', RefScreenSize ) ;
set(ButtonHandle, 'Tag','CancelButton', 'string', ButtonString{1}, ...
'Callback',['close(gcbf) ;'] ) ;
ButtonXPos = ButtonPosition(1) - ButtonWidth - TabSpace * 1 ;
ButtonPosition = [ButtonXPos ButtonYPos ButtonWidth TextHeight] ;
% generate the pushbutton: Default .
ButtonHandle = com_Uicontrol( FigureHandle, ButtonPosition, 'Pushbutton', RefScreenSize ) ;
set(ButtonHandle, 'Tag','OKButton', 'string', ButtonString{2}, ...
'Callback', ['link_EditMultiUEParameter(''OKButton_Callback'',gcbo)'] ) ;
handles = guihandles( FigureHandle ) ;
guidata( FigureHandle, handles ) ;
% --------------------------------------------------------------------------
function init_FigureContent( h )
handles = guidata( h ) ;
% get the data in the figure .
MultiUEParameter = getappdata( handles.EditMultiUEParameter, 'MultiUEParameter' ) ;
TagIndex = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789' ;
for num = 1:4
% get the handles of related current UEClass Index .
CheckboxHandle = getfield( handles, ['UEClassCheckbox', TagIndex(num)] ) ;
% update the properties of the Checkbox .
set( CheckboxHandle, 'String', MultiUEParameter(num).DataRateName, ...
'Value', MultiUEParameter(num).Enable ) ;
% update the states of the related uicontrols .
UEClassCheckbox_Callback( CheckboxHandle ) ;
end
% update the strings of the edits .
link_DisplayUEClassInformation( h, MultiUEParameter ) ;
% call the function to set the states of the uicontrols .
UENumberPercentValue = strcmp( MultiUEParameter(1).SelectedPercent, 'UENumberPercent' ) ;
if (UENumberPercentValue == 1)
UENumberPercent_Callback( h ) ;
else
ThroughputPercent_Callback( h ) ;
end
% ------------------------------------------------------------------------------
function link_DisplayUEClassInformation( h, MultiUEParameter ) ;
% upadate the strings of the edits .
handles = guidata( h ) ;
TagIndex = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789' ;
for num = 1: length( MultiUEParameter )
% get the handles of related current UEClass Index .
UENumberPercentHandle = getfield( handles, ['UENumberPercentEdit', TagIndex(num)] ) ;
ThroughputPercentHandle = getfield( handles, ['ThroughputPercentEdit', TagIndex(num)] ) ;
% update the properties of the edits .
set( UENumberPercentHandle, 'String', sprintf( '%0.1f', MultiUEParameter(num).UENumberPercent *100) ) ;
set( ThroughputPercentHandle, 'String', sprintf( '%0.1f', MultiUEParameter(num).ThroughputPercent *100) ) ;
end
% --------------------------------------------------------------------------
function UENumberPercent_Callback( h )
handles = guidata( h ) ;
% get the data in the figure .
MultiUEParameter = getappdata( handles.EditMultiUEParameter, 'MultiUEParameter' ) ;
MultiUEParameter(1).SelectedPercent = 'UENumberPercent' ;
% save the data in the figure .
setappdata( handles.EditMultiUEParameter, 'MultiUEParameter', MultiUEParameter ) ;
% get the index of Enable uicontrols .
EnableUEClassIndex = find( [MultiUEParameter.Enable] ) ;
EnableUicontrolsIndex = [1, (EnableUEClassIndex + 1)] ;
% get the all kinds of handles.
UENumberPercentHandles = getappdata( handles.EditMultiUEParameter, 'UENumberPercentHandles' ) ;
ThroughputPercentHandles = getappdata( handles.EditMultiUEParameter, 'ThroughputPercentHandles' ) ;
% reset the states of the radioboxes .
set( handles.UENumberPercent, 'Value', 1) ;
set( handles.ThroughputPercent, 'Value', 0) ;
set( UENumberPercentHandles( EnableUicontrolsIndex ), 'Enable', 'on' ) ;
set( ThroughputPercentHandles, 'Enable', 'off' ) ;
% 重设UEClass百分比编辑框的活动状态。
link_ResetUEClassEditEnable( h ) ;
% --------------------------------------------------------------------------
function ThroughputPercent_Callback( h )
handles = guidata( h ) ;
% get the data in the figure .
MultiUEParameter = getappdata( handles.EditMultiUEParameter, 'MultiUEParameter' ) ;
MultiUEParameter(1).SelectedPercent = 'ThroughputPercent' ;
% save the data in the figure .
setappdata( handles.EditMultiUEParameter, 'MultiUEParameter', MultiUEParameter ) ;
% get the index of Enable uicontrols .
EnableUEClassIndex = find( [MultiUEParameter.Enable] ) ;
EnableUicontrolsIndex = [1, (EnableUEClassIndex + 1)] ;
% get the all kinds of handles.
UENumberPercentHandles = getappdata( handles.EditMultiUEParameter, 'UENumberPercentHandles' ) ;
ThroughputPercentHandles = getappdata( handles.EditMultiUEParameter, 'ThroughputPercentHandles' ) ;
% reset the states of the radioboxes .
set( handles.UENumberPercent, 'Value', 0) ;
set( handles.ThroughputPercent, 'Value', 1) ;
set( UENumberPercentHandles, 'Enable', 'off' ) ;
set( ThroughputPercentHandles( EnableUicontrolsIndex ), 'Enable', 'on' ) ;
% 重设UEClass百分比编辑框的活动状态。
link_ResetUEClassEditEnable( h ) ;
% --------------------------------------------------------------------------
function UEClassCheckbox_Callback( h )
handles = guidata( h ) ;
% get the data in the figure .
MultiUEParameter = getappdata( handles.EditMultiUEParameter, 'MultiUEParameter' ) ;
TagIndex = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789' ;
% get the tag and the index .
UicontrolTag = get( h ,'Tag' ) ;
UEClassIndex = findstr( TagIndex, UicontrolTag(end) ) ;
% get the index of Enable uicontrols .
EnableUEClassIndex = find( [MultiUEParameter.Enable] ) ;
if (length( EnableUEClassIndex ) == 1 ) & (EnableUEClassIndex(1) == UEClassIndex)
MultiUEParameter(UEClassIndex).Enable = 1 ;
MultiUEParameter(UEClassIndex).UENumberPercent = 1 ;
MultiUEParameter(UEClassIndex).ThroughputPercent = 1 ;
% 必须保证有一个业务,即必须至少选择一类UEClass。
% 故最后一类UEClass的复选框必须处于选中状态。
set( h, 'Value', 1 ) ;
else
% get the value of the checkbox .
MultiUEParameter(UEClassIndex).Enable = get( h, 'Value' ) ;
% 取消某种UEClass时,其所分配的UENumber或者吞吐量百分比应当重设为0。
if (MultiUEParameter(UEClassIndex).Enable == 0) ;
MultiUEParameter(UEClassIndex).UENumberPercent = 0 ;
MultiUEParameter(UEClassIndex).ThroughputPercent = 0 ;
% 将剩下的UEClass重新进行“归一”处理。因未选的UEClass值为0,故参与运算不影响结果。
TotalUENumberPercent = sum( [MultiUEParameter.UENumberPercent] ) ;
TotalThroughputPercent = sum( [MultiUEParameter.ThroughputPercent] ) ;
if (TotalUENumberPercent == 0) | (TotalThroughputPercent == 0)
% get the index of Enable uicontrols .
EnableUEClassIndex = find( [MultiUEParameter.Enable] ) ;
MultiUEParameter(EnableUEClassIndex(1)).UENumberPercent = 1 ;
MultiUEParameter(EnableUEClassIndex(1)).ThroughputPercent = 1 ;
TotalUENumberPercent = 1 ;
TotalThroughputPercent = 1 ;
else
end
for num = 1: length( MultiUEParameter )
MultiUEParameter(num).UENumberPercent = MultiUEParameter(num).UENumberPercent / TotalUENumberPercent ;
MultiUEParameter(num).ThroughputPercent = MultiUEParameter(num).ThroughputPercent / TotalThroughputPercent ;
end
% update the strings of the edits .
link_DisplayUEClassInformation( h, MultiUEParameter ) ;
end
end
% save the data in the figure .
setappdata( handles.EditMultiUEParameter, 'MultiUEParameter', MultiUEParameter ) ;
% get the handles of related current UEClass Index .
UENumberPercentHandle = getfield( handles, ['UENumberPercentEdit', TagIndex(UEClassIndex)] ) ;
ThroughputPercentHandle = getfield( handles, ['ThroughputPercentEdit', TagIndex(UEClassIndex)] ) ;
UEParameterButtonHandle = getfield( handles, ['UEParameterButton', TagIndex(UEClassIndex)] ) ;
% reset the states of the uicontrols .
if (MultiUEParameter(UEClassIndex).Enable == 1)
set( UENumberPercentHandle, 'Enable', 'on' ) ;
set( ThroughputPercentHandle, 'Enable', 'on' ) ;
set( UEParameterButtonHandle, 'Enable', 'on' ) ;
else
set( UENumberPercentHandle, 'Enable', 'off' ) ;
set( ThroughputPercentHandle, 'Enable', 'off' ) ;
set( UEParameterButtonHandle, 'Enable', 'off' ) ;
end
% call the function to set the states of the uicontrols .
UENumberPercentValue = get( handles.UENumberPercent, 'Value' ) ;
if (UENumberPercentValue == 1)
UENumberPercent_Callback( h ) ;
else
ThroughputPercent_Callback( h ) ;
end
% 重设UEClass百分比编辑框的活动状态。
link_ResetUEClassEditEnable( h ) ;
% --------------------------------------------------------------------------
function EditUENumberPercent_Callback( h )
handles = guidata( h ) ;
% get the data in the figure .
MultiUEParameter = getappdata( handles.EditMultiUEParameter, 'MultiUEParameter' ) ;
% get the index of Enable uicontrols .
EnableUEClassIndex = find( [MultiUEParameter.Enable] ) ;
% get the active part of MultiUEParameter.
EnableMultiUEParameter = MultiUEParameter( EnableUEClassIndex ) ;
% get the number of the enable UEClass .
UEClassNumber = length( EnableMultiUEParameter ) ;
TagIndex = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789' ;
% get the tag and the index .
UicontrolTag = get( h ,'Tag' ) ;
UEClassIndex = findstr( TagIndex, UicontrolTag(end) ) ;
% 修正UEClassIndex为其在EnableMultiUEParameter中的序号。
TempUEClassIndex = find( EnableUEClassIndex == UEClassIndex ) ;
if TempUEClassIndex == 1
MaxPercent = 1 * 100 ;
else
% 得到当前UEClass之前的所有UEClass的百分数构成的向量。
FrontalUENumberPercentArray = [EnableMultiUEParameter(1: (TempUEClassIndex - 1) ).UENumberPercent];
% 计算前面UEClass已经占用的百分比。
FrontalUENumberPercentTotal = sum( FrontalUENumberPercentArray );
% 计算此UEClass最多可以达到的百分比。
MaxPercent = (1 - FrontalUENumberPercentTotal) * 100 ;
end
SoftLanguage = 'Chinese' ;
if strcmp( SoftLanguage, 'English' )
ParameterName = 'Throughput Percent [%]' ;
elseif strcmp( SoftLanguage, 'Chinese' )
ParameterName = '吞吐量百分数[%]' ;
else
return ;
end
% get the edit's string
EditValue = get( h, 'String' ) ;
EditValue = str2num( EditValue ) ;
% check the input .
EditValue = com_JudgeInputNumber( EditValue, 'limit', ParameterName, 0, MaxPercent ) ;
if isempty( EditValue )
return ;
else
end
% recaculate the oher data . 除以100即为其真实的百分比。
EnableMultiUEParameter(TempUEClassIndex).UENumberPercent = EditValue / 100 ;
% 计算剩下的百分比。
LeaveUEClassPercent = MaxPercent - EditValue ;
if TempUEClassIndex + 1 <= UEClassNumber
% 将剩下的百分比全部分配给下一个UEClass。 除以100即为其真实的百分比。
EnableMultiUEParameter(TempUEClassIndex + 1).UENumberPercent = LeaveUEClassPercent / 100 ;
end
if (TempUEClassIndex + 2) <= UEClassNumber
% 清楚后面所有UEClass的分布。
for num = (TempUEClassIndex + 2) : UEClassNumber
EnableMultiUEParameter(num).UENumberPercent = 0 ;
end
end
% 数学原理:
% ∑(TotalThroughput * ThroughputPercent / DataRate / ActivityFactor) = TotalUENumer ; % 此行暂时不用。
% 推理如下:
% ∑(TotalUENumer * UENumberPercent * DataRate * ActivityFactor) = TotalThroughput ;
% 假设TotalUENumer = 1;
% 即∑(UENumberPercent * DataRate) = TotalThroughput ;
% 采用归一算法即可得到每一UEClass的ThroughputPercent。
%
UENumberPercentArray = [EnableMultiUEParameter.UENumberPercent] ;
DataRateArray = [EnableMultiUEParameter.DataRate] ;
ActivityFactorArray = [EnableMultiUEParameter.ActivityFactor] ;
ThroughputPercentArray = UENumberPercentArray .* (DataRateArray .* ActivityFactorArray) ;
% 计算总的吞吐量。
TotalThroughput = sum(ThroughputPercentArray) ;
% 重新计算每一类UEClass的吞吐量的百分比。
ThroughputPercentArray = ThroughputPercentArray / TotalThroughput ;
for num = 1: UEClassNumber
EnableMultiUEParameter(num).ThroughputPercent = ThroughputPercentArray(num) ;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -