📄 weibozuoye.m
字号:
function weibozuoye(action)
%微波试验——长线理论
%组号:2
%制作人员:陈立江33026112
%同组人员:王江宁33026104
% 李丹丹33026106
if nargin<1,
action='initialize';
end;
if strcmp(action,'initialize'),
oldFigNumber=watchon;
figNumber=figure( ...
'Visible','on', ...
'NumberTitle','off', ...
'menubar','none', ...
'Name','长线理论');
axes( ...
'Units','normalized', ...
'Position',[0.07 0.45 0.60 0.50]);
%===================================
% Set up the MiniCommand Window
top=0.35;
left=0.05;
right=0.70;
bottom=0.05;
labelHt=0.05;
spacing=0.005;
% First, the MiniCommand Window frame
frmBorder=0.02;
frmPos=[left-frmBorder bottom-frmBorder ...
(right-left)+2*frmBorder (top-bottom)+2*frmBorder];
uicontrol( ...
'Style','frame', ...
'Units','normalized', ...
'Position',frmPos, ...
'BackgroundColor',[0.50 0.60 0.50]);
% Then the text label
labelPos=[left top-labelHt (right-left) labelHt];
uicontrol( ...
'Style','text', ...
'Units','normalized', ...
'Position',labelPos, ...
'BackgroundColor',[0.20 0.20 0.50], ...
'ForegroundColor',[1 1 0.2], ...
'String','先选定功能后修改参数');
% Then the editable text field
mcwPos=[left bottom (right-left) top-bottom-labelHt-spacing];
mcwHndl=uicontrol( ...
'Style','edit', ...
'HorizontalAlignment','left', ...
'Units','normalized', ...
'Max',50, ...
'BackgroundColor',[1 1 0.5], ...
'Position',mcwPos, ...
'Callback','weibozuoye(''quickeval'')', ...
'String',' % Press buttons at the right for example plots.');
% Save this handle for future use
set(gcf,'UserData',mcwHndl);
%====================================
% Information for all buttons
labelColor=[0.8 0.8 0.8];
top=0.95;
bottom=0.05;
left=0.75;
yInitLabelPos=0.90;
left=0.75;
labelWid=0.20;
labelHt=0.05;
btnWid=0.20;
btnHt=0.05;
% Spacing between the label and the button for the same command
btnOffset=0.003;
% Spacing between the button and the next command's label
spacing=0.05;
%====================================
% The CONSOLE frame
frmBorder=0.02;
yPos=0.05-frmBorder;
frmPos=[left-frmBorder yPos btnWid+2*frmBorder 0.9+2*frmBorder];
h=uicontrol( ...
'Style','frame', ...
'Units','normalized', ...
'Position',frmPos, ...
'BackgroundColor',[0.50 0.50 0.50]);
%====================================
% The 电压电流幅值参数 command popup button
btnNumber=1;
yLabelPos=top-(btnNumber-1)*(btnHt+labelHt+spacing);
labelStr=' 电压电流幅值参数';
labelList=' U(z)| I(z)| Ui(z)| Ur(z)| Ii(z)| Ir(z)| U(z)与I(z)| Ui(z)与Ur(z)| Ui(z)与Ii(z)| Ur(z)与Ir(z)';
cmdList=str2mat( ...
'plot(z,(U.*conj(U)).^0.5);set(gca,''XDir'',''reverse'',''YDir'',''normal'');', ...
'plot(z,(I.*conj(I)).^0.5);set(gca,''XDir'',''reverse'',''YDir'',''normal''); ', ...
'plot(z,(Ui.*conj(Ui)).^0.5);set(gca,''XDir'',''reverse'',''YDir'',''normal'');', ...
'plot(z,(Ur.*conj(Ur)).^0.5);set(gca,''XDir'',''reverse'',''YDir'',''normal''); ', ...
'plot(z,(Ii.*conj(Ii)).^0.5);set(gca,''XDir'',''reverse'',''YDir'',''normal'');', ...
'plot(z,(Ir.*conj(Ir)).^0.5);set(gca,''XDir'',''reverse'',''YDir'',''normal'');', ...
'plot(z,(U.*conj(U)).^0.5,z,(I.*conj(I)).^0.5);set(gca,''XDir'',''reverse'',''YDir'',''normal''); ', ...
'plot(z,(Ui.*conj(Ui)).^0.5,z,(Ur.*conj(Ur)).^0.5);set(gca,''XDir'',''reverse'',''YDir'',''normal''); ', ...
'plot(z,(Ui.*conj(Ui)).^0.5,z,(Ii.*conj(Ii)).^0.5);set(gca,''XDir'',''reverse'',''YDir'',''normal''); ', ...
'plot(z,(Ur.*conj(Ur)).^0.5,z,(Ir.*conj(Ir)).^0.5);set(gca,''XDir'',''reverse'',''YDir'',''normal''); ', ...
'plot(z,(Ir.*conj(Ir)).^0.5);set(gca,''XDir'',''reverse'',''YDir'',''normal''); ');
callbackStr='weibozuoye eval';
% Generic label information
labelPos=[left yLabelPos-labelHt labelWid labelHt];
uicontrol( ...
'Style','text', ...
'Units','normalized', ...
'Position',labelPos, ...
'BackgroundColor',labelColor, ...
'HorizontalAlignment','left', ...
'String',labelStr);
% Generic popup button information
btnPos=[left yLabelPos-labelHt-btnHt-btnOffset btnWid btnHt];
hndl1=uicontrol( ...
'Style','popup', ...
'Units','normalized', ...
'Position',btnPos, ...
'String',labelList, ...
'Callback',callbackStr, ...
'UserData',cmdList);
%====================================
% The 阻抗导纳参数 command popup button
btnNumber=2;
yLabelPos=top-(btnNumber-1)*(btnHt+labelHt+spacing);
labelStr=' 阻抗导纳参数';
labelList=' 缺省| R(z)| X(z)| G(z)| B(z)| R(z)与X(z)| G(z)与B(z)| R(GAMA)| X(GAMA)| G(GAMA)| B(GAMA)';
cmdList=str2mat( ...
' ', ...
'plot(z,real(Zin));set(gca,''XDir'',''reverse'',''YDir'',''normal'');', ...
'plot(z,imag(Zin));set(gca,''XDir'',''reverse'',''YDir'',''normal'');', ...
'plot(z,real(1./Zin));set(gca,''XDir'',''reverse'',''YDir'',''normal'');', ...
'plot(z,imag(1./Zin));set(gca,''XDir'',''reverse'',''YDir'',''normal'');',...
'plot(z,real(Zin),z,imag(Zin));set(gca,''XDir'',''reverse'',''YDir'',''normal'');', ...
'plot(z,real(1./Zin),z,imag(1./Zin));set(gca,''XDir'',''reverse'',''YDir'',''normal'');',...
'colormap(hsv(44));z = cplxgrid(34);cplxmap(z,(1+z)./(1-z)); %观察输入电阻随反射系数变化的情况',...
'colormap(hsv(44));z = cplxgrid(34);cplxmap(z,-j*(1+z)./(1-z)); %观察输入电抗随反射系数变化的情况',...
'colormap(hsv(44));z = cplxgrid(34);cplxmap(z,(1-z)./(1+z)); %观察输入电导随反射系数变化的情况',...
'colormap(hsv(44));z = cplxgrid(34);cplxmap(z,-j*(1-z)./(1+z)); %观察输入电纳随反射系数变化的情况');
callbackStr='weibozuoye eval';
% Generic label information
labelPos=[left yLabelPos-labelHt labelWid labelHt];
uicontrol( ...
'Style','text', ...
'Units','normalized', ...
'Position',labelPos, ...
'BackgroundColor',labelColor, ...
'HorizontalAlignment','left', ...
'String',labelStr);
% Generic popup button information
btnPos=[left yLabelPos-labelHt-btnHt-btnOffset btnWid btnHt];
hndl2=uicontrol( ...
'Style','popup', ...
'Units','normalized', ...
'Position',btnPos, ...
'String',labelList, ...
'Callback',callbackStr, ...
'UserData',cmdList);
%====================================
% The 其它参数 command popup button
btnNumber=3;
yLabelPos=top-(btnNumber-1)*(btnHt+labelHt+spacing);
labelStr='其它参数';
labelList=' 缺省| 反射系数| 驻波比| 行波系数| 入射功率| 反射功率| 入射功率与反射功率| 总功率';
cmdList=str2mat( ...
' ', ...
'plot(z,(GAMA.*conj(GAMA)).^0.5);set(gca,''XDir'',''reverse'',''YDir'',''normal'');', ...
'plot(z,row);set(gca,''XDir'',''reverse'',''YDir'',''normal'');', ...
'plot(z,1./row);set(gca,''XDir'',''reverse'',''YDir'',''normal'');', ...
'plot(z,Pi);set(gca,''XDir'',''reverse'',''YDir'',''normal''); ',...
'plot(z,-Pr);set(gca,''XDir'',''reverse'',''YDir'',''normal''); ',...
'plot(z,Pi,z,-Pr);set(gca,''XDir'',''reverse'',''YDir'',''normal''); ',...
'plot(z,P);set(gca,''XDir'',''reverse'',''YDir'',''normal''); ' );
callbackStr='weibozuoye eval';
% Generic label information
labelPos=[left yLabelPos-labelHt labelWid labelHt];
uicontrol( ...
'Style','text', ...
'Units','normalized', ...
'Position',labelPos, ...
'BackgroundColor',labelColor, ...
'HorizontalAlignment','left', ...
'String',labelStr);
% Generic popup button information
btnPos=[left yLabelPos-labelHt-btnHt-btnOffset btnWid btnHt];
hndl3=uicontrol( ...
'Style','popup', ...
'Units','normalized', ...
'Position',btnPos, ...
'String',labelList, ...
'Callback',callbackStr, ...
'UserData',cmdList);
%====================================
% The 其它 command popup button
btnNumber=4;
yLabelPos=top-(btnNumber-1)*(btnHt+labelHt+spacing);
labelStr=' 其它';
labelList=' grid| x grid| y grid| nogrid| semilogx| semilogy| semilogz| loglog';
cmdList=str2mat( ...
' set(gca,''XGrid'',''on'',''YGrid'',''on'');', ...
' set(gca,''XGrid'',''on'',''YGrid'',''off'');', ...
' set(gca,''XGrid'',''off'',''YGrid'',''on'');', ...
' set(gca,''XGrid'',''off'',''YGrid'',''off'');',...
' set(gca,''XScale'',''log'',''YScale'',''linear'');', ...
' set(gca,''XScale'',''linear'',''YScale'',''log'');', ...
' set(gca,''XScale'',''linear'',''YScale'',''linear'',''ZScale'',''log'');', ...
' set(gca,''XScale'',''log'',''YScale'',''log'');');
callbackStr='weibozuoye eval';
% Generic label information
labelPos=[left yLabelPos-labelHt labelWid labelHt];
uicontrol( ...
'Style','text', ...
'Units','normalized', ...
'Position',labelPos, ...
'BackgroundColor',labelColor, ...
'HorizontalAlignment','left', ...
'String',labelStr);
% Generic popup button information
btnPos=[left yLabelPos-labelHt-btnHt-btnOffset btnWid btnHt];
hndl4=uicontrol( ...
'Style','popup', ...
'Units','normalized', ...
'Position',btnPos, ...
'String',labelList, ...
'Callback',callbackStr, ...
'UserData',cmdList);
%====================================
uicontrol( ...
'Style','pushbutton', ...
'Units','normalized', ...
'Position',[left bottom+2*btnHt+spacing btnWid 2*btnHt], ...
'String','刷新', ...
'Callback','weibozuoye(''info'')');
% The close button.
uicontrol( ...
'Style','pushbutton', ...
'Units','normalized', ...
'Position',[left bottom btnWid 2*btnHt], ...
'String','关闭', ...
'Callback','close(gcf)');
% Uncover the figure
hndlList=[mcwHndl hndl1 hndl2 hndl3 hndl4];
watchoff(oldFigNumber);
set(figNumber,'Visible','on', ...
'UserData',hndlList);
weibozuoye('eval');
elseif strcmp(action,'info'),
hndlList=get(gcf,'UserData');
mcwHndl=hndlList(1);
evalmcw(mcwHndl);
elseif strcmp(action,'quickeval'),
% Execute the MiniCommand Window text exactly as it is now.
hndlList=get(gcf,'UserData');
mcwHndl=hndlList(1);
evalmcw(mcwHndl);
elseif strcmp(action,'eval'),
% Assemble and execute the completed command
hndlList=get(gcf,'UserData');
n=length(hndlList);
mcwHndl=hndlList(1);
evalStr=str2mat(...
'Rl=2; %设定负载电阻',...
'Xl=2; %设定负载电抗',...
'U2=2*exp(j*pi/3); %设定终端电压', ...
'arfa=0.02; %设定衰减常数', ...
'beta=2*pi; %设定相移常数', ...
'Z0=1; %设定长线特性阻抗', ...
'lgi=1; %设定长线归一化长度', ...
'lamda=2*pi/beta; %求出传播波长', ...
'l=lgi*lamda; %求出长线长度', ...
'gama=arfa+j*beta; %求出传播常数', ...
'if Rl==0,Rl=exp(-32);end', ...
'if Xl==0,Xl=exp(-32);end %零值处理', ...
'Zl=Rl+j*Xl; %求出负载阻抗', ...
'I2=U2./Zl; %求出终端电流', ...
'z=0:lamda/100:l;', ...
'U=U2*cosh(gama*z)+I2*Z0*sinh(gama*z); %求出沿线电压', ...
'I=I2*cosh(gama*z)+U2/Z0*sinh(gama*z); %求出沿线电流', ...
'Zin=U./I; %求出沿线输入阻抗', ...
'Zgi=Zin/Z0; %求出沿线归一化阻抗', ...
'GAMA=(Zgi-1)./(Zgi+1); %求出沿线反射系数', ...
'GAMA2=(GAMA.*conj(GAMA)).^0.5;',...
'row=(1+GAMA2)./(1-GAMA2); %求出沿线驻波比',...
'Ui=U2/(1+GAMA(1,1))*exp(gama*z); %求出沿线入射电压',...
'Ur=U2/(1+GAMA(1,1))*GAMA(1,1)*exp(-gama*z); %求出沿线反射电压',...
'Ii=U2/(1+GAMA(1,1))*exp(gama*z)/Z0; %求出沿线入射电流',...
'Ir=-U2/(1+GAMA(1,1))*GAMA(1,1)*exp(-gama*z)/Z0; %求出沿线反射电流',...
'Pi=real((Ui.*conj(Ii)))/2; %求出沿线入射功率', ...
'Pr=real((Ur.*conj(Ir)))/2; %求出沿线反射功率', ...
'P=Pi+Pr; %求出沿线总功率');
for count=2:n,
newStrList=get(hndlList(count),'UserData');
newStrVal=get(hndlList(count),'Value');
newStr=deblank(newStrList(newStrVal,:));
if ~isempty(newStr), evalStr=str2mat(evalStr,newStr); end;
end;
set(mcwHndl,'String',evalStr);
evalmcw(mcwHndl);
end;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -