Inner matrix dimensions must agree?
2 views (last 30 days)
Show older comments
I am trying to graph the magnitude and phase of this equation, and I keep getting that error.
I am a matlab newbie, no clue what's wrong at all.
%USER
w = [-25:25]*pi/25;
T = [-25:25];
X = -(2*1i*exp(-(1/2)*1i*T*w)*(-1+exp((1i* T* w)/2))*(-2+T))/(T*w);
magX = abs(X); phaX = angle(X);
In case it helps here is the function I am trying to graph in a more readable form.
0 Comments
Answers (2)
Azzi Abdelmalek
on 2 Jul 2014
Edited: Azzi Abdelmalek
on 2 Jul 2014
When you multiply or divide two vectors, element by element, you need to add a dot (.) before your operator, in your case: .* and ./
w = [-25:25]*pi/25;
T = [-25:25];
X = -(2*1i*exp(-(1/2)*1i*T.*w).*(-1+exp((1i* T.* w)/2)).*(-2+T))./(T.*w);
0 Comments
Joseph Cheng
on 2 Jul 2014
What is happening is that you're performing matrix multiplication in your X = equation. which isn't what you want to do here. you need to perform the Element by element multiplication that Azzi has shown. this is performed by the '.*' which means for each element of w it will be multiplied by the same element in T. such that w.*T = [w(1)*T(1) w(2)*T(2) .... w(n)*T(n)].
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!