Matrix dimension must agree

2 次查看(过去 30 天)
Muhammad Fauzan
Muhammad Fauzan 2020-11-17
回答: Ameer Hamza 2020-11-17
w = [0:1:500]*pi/500;
X = exp(j*w)./(exp(j.*w) - 0.5.*ones(1,500));
magx = abs(X); angX = angel(X);
subplot(2,2,1); plot(w/pi,magX); grid
xlabel('frequency in pi units'); title('Magnitude Part'); ylabel('Magnitude')
subplot(2,2,3); plot(w/pi,angX); grid
xlabel('frequency in pi units'); title('Angel Part'); ylabel('Radians')
subplot(2,2,2); plot(w/pi,realX); grid
xlabel('frequency in pi units'); title('Real Part'); ylabel('Real')
subplot(2,2,4); plot(w/pi,imagX); grid
xlabel('frequency in pi units'); title('Imaginary Part'); ylabel('Imaginary')
ERROR:
Error using -
Matrix dimensions must agree.

回答(2 个)

Alan Stevens
Alan Stevens 2020-11-17
w is size 1x501 not 1x500.

Ameer Hamza
Ameer Hamza 2020-11-17
There are several syntax error in your code. Compare following with your code to see the mistakes.
w = (0:1:500)*pi/500;
X = exp(1j*w)./(exp(1j.*w) - 0.5.*ones(1,501));
magx = abs(X); angX = angle(X);
realX = real(X); imagX = imag(X);
subplot(2,2,1); plot(w/pi,magx); grid
xlabel('frequency in pi units'); title('Magnitude Part'); ylabel('Magnitude')
subplot(2,2,3); plot(w/pi,angX); grid
xlabel('frequency in pi units'); title('Angel Part'); ylabel('Radians')
subplot(2,2,2); plot(w/pi,realX); grid
xlabel('frequency in pi units'); title('Real Part'); ylabel('Real')
subplot(2,2,4); plot(w/pi,imagX); grid
xlabel('frequency in pi units'); title('Imaginary Part'); ylabel('Imaginary')

类别

Help CenterFile Exchange 中查找有关 Title 的更多信息

产品


版本

R2014a

Community Treasure Hunt

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

Start Hunting!

Translated by