Hi,
I am very new to the Matlab. I made one function which gives me an array of sinusoids. In arguments, I am providing an array of amplitude, frequency and phase. The other arguments are length and sampling frequency. When I call the function from command line I am getting error mentioned in the title. I have also tried with the .* method.
Can some one guide me the solve the problem?
Thanks.
Error:
Matrix dimensions must agree.
Error in generateSin (line 5)
function [z] = generateSin (a,f, ph,L, Fs)
T = 1/Fs;
tmax = L*T;
t = 0:T:tmax-T;
z = a.*sin (2*pi*t.*f + ph)
end
%command line function call sample : z = generateSin ([3,5,7], [5,10,15], [0,pi/2, pi/6], 1000, 300)

댓글 수: 1

Torsten
Torsten 2019년 7월 29일
t is a vector of length 1000, a, f and ph are vectors of length 3. What dimension do you expect z to have ?

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

 채택된 답변

Andrei Bobrov
Andrei Bobrov 2019년 7월 29일
편집: Andrei Bobrov 2019년 7월 29일

1 개 추천

function [z] = generateSin (a,f, ph,L, Fs)
z = (a(:).*sin (2*pi*(0:L-1)/Fs).*f(:) + ph(:))';
end

댓글 수: 2

Ravikumar Mevada
Ravikumar Mevada 2019년 7월 29일
Hi,
Can you please explain, Why you have inserted ' at the end of the fourth line?
Andrei Bobrov
Andrei Bobrov 2019년 7월 29일
First please read part of help from MATLAB Getting Started.
In our case " ' " - sign transpoze our array.

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Elementary Math에 대해 자세히 알아보기

질문:

2019년 7월 29일

댓글:

2019년 7월 29일

Community Treasure Hunt

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

Start Hunting!

Translated by