Why do I get Error using * Inner matrix dimensions must agree.

This is my code.
t = [-4: 0.01: 3.99];
A_c = 1;
f_c = 50;
m_t = sinc(2 * (t - 2)) - sinc(2 * (t + 2));
k_a = input('enter the value of k_a: ');
s_t = A_c * (1 + k_a * m_t) * cos(2 * pi * f_c * t);
idx = (t >= -2.5 & t <= -1.5);
hold on
plot(t(idx), s_t(idx), '.r');

Réponses (1)

Image Analyst
Image Analyst le 31 Mar 2018
Modifié(e) : Image Analyst le 31 Mar 2018
Use"dot star" instead of "star" to do element by element multiplication instead of matrix multiplication:
s_t = A_c * (1 + k_a * m_t) .* cos(2 * pi * f_c * t);

3 commentaires

OK, that gave me this error
Error: File: exercise_1_b.m Line: 8 Column: 28
Unexpected MATLAB operator.
this is my code
t = [-2.5: 0.01: -1.5];
A_c = 1;
f_c = 50;
m_t = sinc(2 * (t - 2)) - sinc(2 * (t + 2));
% b)
k_a = input('enter the value of k_a: ');
s_t = A_c * (1 + k_a * m_t). * cos(2 * pi * f_c * t);
plot(t, s_t);
You didn't do it right. You have no space between the ) and the dot and you have a space after the dot. Do it like I did "space dot star space"
that worked
thank you so much

Connectez-vous pour commenter.

Catégories

Question posée :

le 31 Mar 2018

Commenté :

le 31 Mar 2018

Community Treasure Hunt

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

Start Hunting!

Translated by