Matrix dimension must agree

1 view (last 30 days)
Muhammad Fauzan
Muhammad Fauzan on 17 Nov 2020
Answered: Ameer Hamza on 17 Nov 2020
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.

Answers (2)

Alan Stevens
Alan Stevens on 17 Nov 2020
w is size 1x501 not 1x500.

Ameer Hamza
Ameer Hamza on 17 Nov 2020
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')

Products


Release

R2014a

Community Treasure Hunt

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

Start Hunting!