Error : Inner matrix dimensions must agree.
1 回表示 (過去 30 日間)
古いコメントを表示
I'm getting an Error saying Inner matrix dimension must agree while trying to multipicate and plot
X = 2*cos(2*f1*pi*t)+sin(2*f2*pi*t)
Y = Ac*cos(Fc*2*pi*t)
Z = X*Y
I don't understand why i'm getting this error
Note : All the variables are defined in the code .
3 件のコメント
Alex Mcaulley
2020 年 1 月 28 日
Probably you want to do an element wise multiplication:
Z = X.*Y;
採用された回答
Image Analyst
2020 年 1 月 28 日
You forgot to give the actual error message! So we don't know which line it bombed on.
I agree with Adam and Alex though. Try .* and if that doesn't work, examine the sizes of all the variables. Of course you know that with a matrix multiplication with X*Y and X is rowsx*colsx and Y is rowsy * colsy, you must have colsx equal rowsy. For example [5*3] * [15*20] won't work but [5*3] * [3 * 20] will work because the inner dimensions are the same (unlike in your case).
Another thing to check is the shape. For example if X is a row vector and Y is a column vector (or vice versa) then multiplying them will not give a vector, even if they're the same length. Due to automatic expansion it will give a rectangular matrix.
1 件のコメント
Image Analyst
2020 年 1 月 28 日
Corrected code needs Y = (1+m*Signal) * Ac .* cos(Fc*2*pi*t)
Try this:
% The Function We have choosen is m(t) = 2cos(100*pi*t)+sin(200*pi*t) %
f1 = 50 ;
f2 = 100 ;
%%Time specifications%%
Fs =300; % samples per second
Ts = 1/Fs ;
t = 0:Ts:1-Ts ; % seconds per sample
Signal = 2*cos(2*f1*pi*t)+sin(2*f2*pi*t);
% ********** Part (1) ********** %
% ****** Plotting Function ***** %
subplot(2, 2, 1) ;
plot(t,Signal);
title('The signal') ;
ylabel('V') ;
xlabel('time');
% Fourier Transform for Function %
F = fft(Signal) ;
F_mag = abs(F) ;
U = Fs/length(F) ;
Fx = -Fs/2:U:Fs/2-U;
subplot(2, 2, 2);
plot(Fx,F_mag/150) ;
title('Fourier Trasform of the function') ;
ylabel('F(f)') ;
xlabel('Frequency (Hz)') ;
%%%%%%%%%%%%%%%%%%%%% DSB_LC %%%%%%%%%%%%%%%%%%
% Carrier %
Fc=70000 ; Ac = 1 ; C = Ac*cos(Fc*2*pi*t) ;
m = 0.25 ; %%Modulation INDEX (1)%%
Y = (1+m*Signal) * Ac .* cos(Fc*2*pi*t) ;
subplot(2, 2, 3:4) ;
plot(t,Y) ;
title('Modulated signal');
ylabel('V');
xlabel('time') ;
その他の回答 (0 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!