Vectors mut be the same length.

9 ビュー (過去 30 日間)
Alisa-Oleksandra Kotliarova
Alisa-Oleksandra Kotliarova 2023 年 12 月 23 日
コメント済み: Sulaymon Eshkabilov 2023 年 12 月 23 日
I have the following code:
% Вектор абцис частотних функцій і кут:
lomega=logspace(-1,1);
pl=lomega*1i;
% Передатна функція:
Wl=k./(T2*T1*p.^2+T1*p+1);
% Модуль передатної функції і її логарифмічний вигляд:
Al=abs(Wl);
L=20*log10(Al);
%Перевод даних в градуси:
fil=angle(Wl);
fil_d=fil.*180./pi;
H=20*log10(fil_d);
figure(3);
subplot(2,1,1);
semilogx (lomega, L), grid on
title('ЛАЧХ');%ЛАЧХ;
xlabel('ω');
ylabel('A');
subplot(2,1,2);
semilogx (lomega, H), grid on
title('ЛФЧХ');%ЛФЧХ;
xlabel('ω');
ylabel('φ');
It only gives:
Error using semilogx
Vectors must be the same length.
Error in Lab3_var5 (line 63)
semilogx (lomega, L), grid on
How can I correct it? Thank you.
  3 件のコメント
Dyuman Joshi
Dyuman Joshi 2023 年 12 月 23 日
編集済み: Dyuman Joshi 2023 年 12 月 23 日
There are many undefined variables in the code above.
The number of elements of the variables (or vectors) to be plotted, lomega and L, are not the same.
To correct the error, make sure both variables have the same number of elements.
Image Analyst
Image Analyst 2023 年 12 月 23 日
What is the size of lomega and H? Evidently they don't have the same number of elements. Do you know how to debug? Look in the workspace panel for the sizes of the variables.

サインインしてコメントする。

採用された回答

Sulaymon Eshkabilov
Sulaymon Eshkabilov 2023 年 12 月 23 日
Check what is the size of the transfer function W1 size at first and then the question becomes clear.
Since k, T1, T2 are not given in your code, just assuming them to be scalars, your code works ok:
lomega=logspace(-1,1);
pl=lomega*1i;
% Assuming these values for k, T1, T2
k = 1;
T1 = 1;
T2 = 2;
p=pl;
% Передатна функція:
Wl=k./(T2*T1*p.^2+T1*p+1);
% Модуль передатної функції і її логарифмічний вигляд:
Al=abs(Wl);
L=20*log10(Al);
%Перевод даних в градуси:
fil=angle(Wl);
fil_d=fil.*180./pi;
H=20*log10(fil_d);
figure(3);
subplot(2,1,1);
semilogx(lomega, L), grid on
title('ЛАЧХ');%ЛАЧХ;
xlabel('ω');
ylabel('A');
subplot(2,1,2);
semilogx(lomega, H), grid on
Warning: Imaginary parts of complex X and/or Y arguments ignored.
title('ЛФЧХ');%ЛФЧХ;
xlabel('ω');
ylabel('φ');
  2 件のコメント
Alisa-Oleksandra Kotliarova
Alisa-Oleksandra Kotliarova 2023 年 12 月 23 日
Thanks, that helped a lot!
Sulaymon Eshkabilov
Sulaymon Eshkabilov 2023 年 12 月 23 日
Most welcome! Glad to help.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeAnnotations についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by