Error using semilogx Vectors must be the same length.

Wondering why I'm getting the error at the end?
clc
close all
R = 10e3;
C = 18e-9;
Wb = 1/(R*C);
A=@ (w) 1./[1 -(Wb./w).^2 - 1i*2*Wb./w];
w = 10:10:1e6;
amp = 20*log10(abs(A(w)));
ang = angle(A(w))*180/pi;
subplot (211)
semilogx(w,amp,'b','linewidth',2)
grid on
title(char(A))
ylabel('Magnitude (DB)')
set(gca,'xscale','log')
subplot(212)
semilogx(w,ang,'r','linewidth',2)
grid on
set(gca,'xscale','log')
xlabel('frequency (rad/sec)')
ylabel ('phase (deg)')
__________________________________________________________________________________________
Error using semilogx
Vectors must be the same length.
Error in lab20cd3 (line 11)
semilogx(abs(w),abs(amp),'b','linewidth',2)

Answers (1)

Use
A=@ (w) 1./(1 -(Wb./w).^2 - 1i*2*Wb./w);
instead of
A=@ (w) 1./[1 -(Wb./w).^2 - 1i*2*Wb./w];

2 Comments

Ah yes, inside [] spacing is important, and [1 -(Wb./w).^2 - 1i*2*Wb./w] would probably be interpreted as
horzcat(1, -(Wb./w).^2-1i*2*Wb./w)

Sign in to comment.

Categories

Asked:

on 22 Apr 2023

Commented:

on 22 Apr 2023

Community Treasure Hunt

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

Start Hunting!