Error in Smith chart code. What needs to be corrected? / What should be the correct code? The code was given to me, and it doesn't run on my laptop.
2 次查看(过去 30 天)
显示 更早的评论
The error indicated by the code is as follows:
Error: File: SmithChart_final.m Line: 12 Column: 1
Function definitions are not permitted in this context.
The purpose of the activity is to create an interface or a program in MATLAB where it's possible to input certain data, which will be used to calculate other values. Subsequently, the goal is to graphically represent these calculations on a Smith chart.
%programa final
clear, clc, close all, format compact
%Ingreso de datos
fprintf('\n Ingrese los datos soliciados en el formato Re+imj')
Z_0=input('\n* Impedancia caracteristica (Z0): ');
Z_L=input('\n* Impedancia de carga (ZL): ');
fprintf('\n Zn se grafica con el punto rojo y Yn con el punto azul \n')
[Zn, Y, coef, vswr, PR, PD] = carta_calculo(Z_0, Z_L)
function carta_grafica
%grafica de carta de smith para ciruclos en "x" y "y"
t = linspace(0, 2*pi, 100);
x = cos(t);
y = sin(t);
plot(x, y,'-g.','linewidth',3,'markersize', 1); axis equal;
title('------------------------ Smith Chart,Carta de Smith------------------------')
set(gca,'xticklabel',{[]});
set(gca,'yticklabel',{[]});
hold on
k = [.25 .5 .75];
for i = 1 : length(k)
x(i,:) = k(i) + (1 - k(i)) * cos(t);
y(i,:) = (1 - k(i)) * sin(t);
plot(x(i,:), y(i,:), 'k')
end
kt = [2.5 pi 3.79 4.22];
k = [.5 1 2 4];
for i = 1 : length(kt)
t = linspace(kt(i), 1.5*pi, 50);
a(i,:) = 1 + k(i) * cos(t);
b(i,:) = k(i) + k(i) * sin(t);
plot(a(i,:), b(i,:),'k', a(i,:), -b(i,:),'k' )
end
end
function [Zn, Yn, coef, vswr, PR, PD] = carta_calculo(Zo, ZL)
carta_grafica
Zn=ZL/Zo;
Yn=1/Zn;
g=(Zn-1)/(Zn+1);
coef=abs(g);
th=angle(g);
ig=1/g;
ith=angle(ig);
%grafica para Zn y Yn
polar(th, coef, 'rx') %zn
polar(-ith, -coef, 'bx') %yn
thd= th * (180/pi);
%VSWR
vswr=abs((1+coef)/(1-coef));
PR =-20*log10(coef);
PD=-10*log10(1-(coef)^2);
end
0 个评论
回答(1 个)
Walter Roberson
2023-11-26
编辑:Walter Roberson
2023-11-26
Your version of MATLAB, R2013a, is too old to be able to have function definitions in script files.
You will need to move function carta_grafica to file carta_grafica.m and need to move function carta_calculo to file carta_calculo.m
Or... you could update to a version of MATLAB that is not a decade old. R2015b is the release that started permitting functions in scripts.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!