generate 100-element row in matlab

조회 수: 7 (최근 30일)
arash rad
arash rad 2022년 6월 30일
댓글: Adam Danz 2022년 6월 30일
Hello,
Can anyone help me with generating this signal s(n)=cos(0.04*pi*n) with 100 element row in matlab
  댓글 수: 1
Adam Danz
Adam Danz 2022년 6월 30일
What have you tried so far? Sounds like you need to use linspace.

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

채택된 답변

Pratyush Swain
Pratyush Swain 2022년 6월 30일
Hey,
I believe you need to store the values of the function in a vector of 100 elements;
%create evenly spaced input values%
n=linspace(0,50,100);
%s is the vector which shall contain the output values%
s=zeros(1,100);
%calculate and store function values%
for i=1:length(n)
s(i)=cos(0.04*pi*n(i));
end
%plot to realise them%
figure;
plot(n,s);
Hope this helps.
  댓글 수: 1
Adam Danz
Adam Danz 2022년 6월 30일
In this case, vectorization would be more efficient and readable.
n = linspace(0,50,100);
s = cos(0.04*pi*n);
plot(n,s)

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Hamming에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by