📄 cnf_update_panel.m
字号:
ty=(Y+Vgap/2-pos(2))/pos(4);
tx=0.01/pos(3);
axes(handles.axes_Panel);
ud.Handles2.EquationHandle =text(tx,ty,...
'\fontsize{12}\bf\it \rho\fontsize{11}\rm\bf (\ite\rm\bf) = -\it\beta \rm\bf| exp(-\it\alpha |e|\rm\bf) - exp(-\it\alpha \rm\bf|\fontsize{10}h(0)\fontsize{11}-r|) |', 'Color','b');
% set(ud.Handles2.EquationHandle, 'Visible','off');
% parameter Alpha in rho function
Y=Y-Vgap;
text_Pos(2)=Y;
ud.Handles2.text_Alpha = uicontrol('Parent',FigHandle, ...
'Unit',Params.StdUnit,...
'BackgroundColor',Params.StdColor, ...
'Position',text_Pos, ...
'String','alpha ', ...
'Style','text',...
'HorizontalAlignment','right');
slider_Pos(2)=Y;
ud.Handles2.slider_Alpha = uicontrol('Parent',FigHandle, ...
'Unit',Params.StdUnit,...
'BackgroundColor',[1 1 1], ...
'Position',slider_Pos, ...
'Style','slider', ...
'Callback',{@callback_slider_edit}, ...
'HorizontalAlignment','left');
edit_Pos(2)=Y;
ud.Handles2.edit_Alpha = uicontrol('Parent',FigHandle, ...
'Unit',Params.StdUnit,...
'BackgroundColor',[1 1 1], ...
'Position',edit_Pos, ...
'Style','edit', ...
'Callback',{@callback_slider_edit}, ...
'HorizontalAlignment','center');
set(ud.Handles2.slider_Alpha,'UserData',ud.Handles2.edit_Alpha);
set(ud.Handles2.edit_Alpha,'UserData',ud.Handles2.slider_Alpha);
% parameter Beta in rho function
Y=Y-Vgap;
text_Pos(2)=Y;
ud.Handles2.text_Beta = uicontrol('Parent',FigHandle, ...
'Unit',Params.StdUnit,...
'BackgroundColor',Params.StdColor, ...
'Position',text_Pos, ...
'String','beta ', ...
'Style','text',...
'HorizontalAlignment','right');
slider_Pos(2)=Y;
ud.Handles2.slider_Beta = uicontrol('Parent',FigHandle, ...
'Unit',Params.StdUnit,...
'BackgroundColor',[1 1 1], ...
'Position',slider_Pos, ...
'Style','slider', ...
'Callback',{@callback_slider_edit}, ...
'HorizontalAlignment','left');
edit_Pos(2)=Y;
ud.Handles2.edit_Beta = uicontrol('Parent',FigHandle, ...
'Unit',Params.StdUnit,...
'BackgroundColor',[1 1 1], ...
'Position',edit_Pos, ...
'Style','edit', ...
'Callback',{@callback_slider_edit}, ...
'HorizontalAlignment','center');
set(ud.Handles2.slider_Beta,'UserData',ud.Handles2.edit_Beta);
set(ud.Handles2.edit_Beta,'UserData',ud.Handles2.slider_Beta);
% set the values
Beta = cnfdb.Controller.CNF_Beta;
set(ud.Handles2.slider_Beta,'Max', max(2*Beta,1) );
set(ud.Handles2.slider_Beta,'Value',Beta);
set(ud.Handles2.edit_Beta,'String', num2str(Beta,'%0.6g') );
Alpha = cnfdb.Controller.CNF_Alpha;
set(ud.Handles2.slider_Alpha,'Max', max(2*Alpha,1) );
set(ud.Handles2.slider_Alpha,'Value',Alpha);
set(ud.Handles2.edit_Alpha,'String', num2str(Alpha,'%0.6g') );
% setup the CNF Weighting Matrix
text_Pos(2)=Y-Vgap*2;
text_Pos(4)=2*text_Pos(4);
ud.Handles2.WM_text=uicontrol('Parent',FigHandle, ...
'Unit',Params.StdUnit,...
'BackgroundColor',Params.StdColor, ...
'ForegroundColor','b',...
'FontWeight','bold',...
'FontSize',10,...
'Position',text_Pos, ...
'String','Matrix W (Diagonal)', ...
'Style','text', ...
'HorizontalAlignment','left');
% for each diagonal element of W
ud.WM_size=0;
while ud.WM_size<ord & Y>Vgap,
ud.WM_size=ud.WM_size+1;
Y=Y-Vgap;
slider_Pos(2)=Y;
ud.WM_slider(ud.WM_size)=uicontrol('Parent',FigHandle, ...
'Unit','normalized ',...
'BackgroundColor',[1 1 1], ...
'Position',slider_Pos, ...
'Style','slider', ...
'Callback',{@callback_slider_edit}, ...
'HorizontalAlignment','left');
edit_Pos(2)=Y;
edit1= uicontrol('Parent',FigHandle, ...
'Unit','normalized ',...
'BackgroundColor',[1 1 1], ...
'Position',edit_Pos, ...
'Style','edit', ...
'Callback',{@callback_slider_edit}, ...
'HorizontalAlignment','center');
set(ud.WM_slider(ud.WM_size), 'UserData',edit1);
set(edit1,'UserData',ud.WM_slider(ud.WM_size) );
end
WM_S=ud.WM_size;
W=cnfdb.Controller.CNF_W; % note that W now is a vector of those diagonal elements
nw = length(W);
if IC>0 & nw<WM_S % now the term for integration is the 1st
W=[0 W];
nw=nw+1;
end
for nn=1:min([nw,WM_S]),
if W(nn)>0
MaxW=2*W(nn);
else
MaxW=1;
end
set(ud.WM_slider(nn), 'Max', MaxW );
set(ud.WM_slider(nn), 'Value', W(nn) );
edit1=get(ud.WM_slider(nn), 'UserData');
set(edit1, 'String', num2str(W(nn),'%0.6g') );
end
end
% re-locate the button
% Pos = get(handles.Button_Start, 'Position');
% Pos(2) =(Y- Pos(4))*0.7;
% set(handles.Button_Start, 'Position', Pos);
% refresh the simulation parameters on the panel
set(handles.edit_SetPoint,'String', num2str(cnfdb.SetPoint,'%0.6g') );
set(handles.edit_StopTime,'String', num2str(cnfdb.StopTime,'%0.6g') );
set(handles.edit_StepSize,'String', num2str(cnfdb.StepSize,'%0.6g') );
set(handles.edit_ErrorBound,'String', num2str(cnfdb.ErrorBound) );
set(handles.check_Percent,'Value', cnfdb.ErrorInPercent );
% Create the lines that will plot the result (r,y,u,x,q) from the simulation
% the lines for (r,h,u,x,q)
[nh,nu] = size(cnfdb.System.D2);
nx = size(cnfdb.System.A);
nq = 0;
if cnfdb.System.QD_in>0
nq=length(cnfdb.System.Q0);
end
nh0 = length(ud.Display.hLineHandles);
nu0 = length(ud.Display.uLineHandles);
nx0 = length(ud.Display.xLineHandles);
ref_val = [0];
out_val = [0];
con_val = [0];
time_val = [0];
x_val = [0];
StyleSet = {'-'; '--'; '-.'; ':'};
ColorSet = 'mbrcykg';
% line (r,h)
if nh > nh0
for i=nh0+1:nh,
lc=ColorSet(mod(i-1,7)+1);
ud.Display.rLineHandles(i) = line(...
'Parent',ud.Display.GraphHandles(1),...
'YData',ref_val,...
'XData',time_val,...
'LineStyle','--',...
'LineWidth',ud.Display.LineWidth,...
'Color',ud.Display.LineColorR,...
'EraseMode','normal');
ud.Display.hLineHandles(i) = line(...
'Parent',ud.Display.GraphHandles(1),...
'YData',out_val,...
'XData',time_val,...
'LineStyle',ud.Display.LineStyle,...
'LineWidth',ud.Display.LineWidth,...
'Color',lc,...
'EraseMode','normal');
end
elseif nh < nh0
for i=nh0:nh+1,
delete(ud.Display.rLineHandles(i) );
delete(ud.Display.hLineHandles(i) );
end
ud.Display.rLineHandles = ud.Display.rLineHandles(1:nh) ;
ud.Display.hLineHandles = ud.Display.hLineHandles(1:nh) ;
end
% first clear the legend, then re-plot
legend(ud.Display.GraphHandles(1),'off');
str='{';
if nh>1
for i=1:nh,
str = [str, '''', ['h',num2str(i)],''','];
end
str(end)='}';
tt = eval(str);
legend(ud.Display.hLineHandles, tt, 4);
elseif nh==1
legend(ud.Display.GraphHandles(1),'r','h',4);
end
% u line
if nu > nu0
for i=nu0+1:nu,
lc=ColorSet(mod(i-1,7)+3);
ud.Display.uLineHandles(i) = line(...
'Parent',ud.Display.GraphHandles(2),...
'YData',[0],...
'XData',[0],...
'LineStyle', '-',...
'LineWidth', ud.Display.LineWidth,...
'Color', lc,...
'EraseMode','normal');
end
elseif nu < nu0
for i=nu0:nu+1,
delete(ud.Display.uLineHandles(i) );
end
ud.Display.uLineHandles = ud.Display.uLineHandles(1:nu) ;
end
% first clear the legend, then re-plot
legend(ud.Display.GraphHandles(2),'off');
str='{';
if nu>1
for i=1:nu,
str = [str, '''', ['u',num2str(i)],''','];
end
str(end)='}';
tt = eval(str);
legend(ud.Display.GraphHandles(2), tt, 4);
end
% (x,q) lines
if nx+nq > nx0
for i=nx0+1:nx+nq,
lc=ColorSet(mod(i-1,7)+1);
% if i>7
% ls=char(StyleSet(mod(i-1,4)+1));
% else
% ls='-';
% end
ii=floor((i-1)/7);
ls=char(StyleSet(mod(ii,4)+1));
ud.Display.xLineHandles(i) = line(...
'Parent',ud.Display.GraphHandles(3),...
'YData',[0],...
'XData',[0],...
'LineWidth', ud.Display.LineWidth,...
'LineStyle', ls,... % '-'
'Color', lc,...
'EraseMode','normal');
end
elseif nx+nq < nx0
for i=nx+nq+1:nx0,
delete(ud.Display.xLineHandles(i) );
end
ud.Display.xLineHandles = ud.Display.xLineHandles(1:nx+nq) ;
end
% first clear the legend, then re-plot
legend(ud.Display.GraphHandles(3),'off');
% str='{';
% if nu>1
% for i=1:nu,
% str = [str, '''', ['u',num2str(i)],''','];
% end
% str(end)='}';
% tt = eval(str);
% legend(ud.Display.GraphHandles(2), tt, 4);
% end
legstr='''x1''';
for i=2:nx
legstr=[legstr,',''x',num2str(i),'''' ];
end
for i=1:nq
legstr=[legstr,',''q',num2str(i),'''' ];
end
if nx+nq>0
eval( ['legend(ud.Display.GraphHandles(3),',legstr,')'] );
end
% save the new handles to AxeHandle
set(AxeHandle,'UserData', ud);
% ------------------------------------------------------------------------
function callback_slider_edit(hObject, eventdata, handles)
% hObject handle to edit_Beta (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
hObject=gcbo;
the_other=get(hObject,'UserData');
switch get(hObject,'Style')
case 'edit'
err_msg = 'The value you just entered is not valid !';
tag=get(hObject,'Tag');
in_str=deblank(get(hObject,'String'));
if isempty(in_str)
error=1;
else
val=evalin('base', in_str ,'[]');
if isnumeric(val) & length(val)==1
error=0;
else
error=1;
end
end
if error==0
if strcmp(tag,'negative') % for negative value
if val <= get(the_other, 'Max')
if val >= get(the_other, 'Min')
set(the_other, 'Value', val);
else
set(the_other, 'Min', 2*val);
set(the_other, 'Value', val);
end
else
error=1;
end
elseif strcmp(tag,'any')
if val >= get(the_other, 'Min') & val <= get(the_other, 'Max')
set(the_other, 'Value', val);
else
lb=get(the_other, 'Min');
ub=get(the_other, 'Max');
set(the_other, 'Min', val-abs(val-(lb+ub)/2), 'Max', val+abs(val-(lb+ub)/2) );
set(the_other, 'Value', val);
end
else % positive is assumed
if val >= get(the_other, 'Min')
if val <= get(the_other, 'Max')
set(the_other, 'Value', val);
else
set(the_other, 'Max', 2*val);
set(the_other, 'Value', val);
end
else
error=1;
end
end
end
if error==1
warndlg(err_msg,'Warning','modal');
uiwait;
val = get(the_other, 'Value');
set(hObject, 'String', num2str(val,'%0.6g'));
end
case 'slider'
val = get(hObject, 'Value');
set(the_other, 'String', num2str(val,'%0.6g'));
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -