Error 'Inner dimensions matrix must agree'
1 view (last 30 days)
Show older comments
I am making a matlab code for my project so I am receiving this "Inner dimnension matrix must agree'. My code is as follows:-
t = 0:0.01:2;%time in seconds
N = 6;%Number of paths
B = [0.2 0.7 0.4 0.3 0.8 0.6];%path gain
Angle = [pi/9 pi/4 pi/6 pi/3 pi/5 pi/2] ;%angles of arrival
varphi = [(1/3)*pi (2/3)*pi (3/3)*pi (4/3)*pi (5/3)*pi (6/3)*pi];%varphi_n for the nth path
fc = 900;%carrier frequency in MHz
fd = 1;%%doppler frequency in Hz
pcpd = varphi-((2*pi*fd)*cos(Angle)*t);%path carrier phase distortion
x = B*exp(j*pcpd);
Please let me know whats going on. Thanks in advance!
2 Comments
the cyclist
on 11 Dec 2017
In the line that gives the error, you are trying to matrix-multiply cos(Angle), which is a vector of length 6, and t, which is a vector of length 201.
What is is that you expect out of that operation?
Kaushik Lakshminarasimhan
on 11 Dec 2017
Edited: Kaushik Lakshminarasimhan
on 11 Dec 2017
Looks like you are trying to compute phase distortion of 6 different paths at 201 different time points. You're getting an error because you are trying to multiply cos(Angle) (a vector of length 6) with t (a vector of length 201).
The correct way to solve this is by computing your variables -- pcpd and x -- for each path at each time point. You can do this using a nested for loop. An alternative (faster) way is to vectorize your code and using the .* operator to perform element-wise multiplication. Either way, it is important to break down the problem into smaller pieces before plugging in the formula.
Answers (0)
See Also
Categories
Find more on Resizing and Reshaping Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!