필터 지우기
필터 지우기

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

답변 (1개)

Walter Roberson
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.

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

제품


릴리스

R2013a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by