Error 'Inner dimensions matrix must agree'

조회 수: 3 (최근 30일)
Humdard
Humdard 2017년 12월 11일
편집: Kaushik Lakshminarasimhan 2017년 12월 11일
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
the cyclist
the cyclist 2017년 12월 11일
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
Kaushik Lakshminarasimhan 2017년 12월 11일
편집: Kaushik Lakshminarasimhan 2017년 12월 11일
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.

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by