필터 지우기
필터 지우기

Save the output of a for loop

조회 수: 3 (최근 30일)
marwa mohamed
marwa mohamed 2020년 9월 10일
댓글: Ameer Hamza 2020년 9월 14일
Hey!
i am trying to generate 3 sine waves with different frequenceies using a for loop. I would like to save the output of this for loop in a matrix 500x3, but it is always overwrite the previous value. can anyone help?
  댓글 수: 1
KSSV
KSSV 2020년 9월 10일
Show us the code....so that we can help you.

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

채택된 답변

Ameer Hamza
Ameer Hamza 2020년 9월 10일
See this example
f = [1 2 3]; % frequencies
t = linspace(0, 10, 500); % time values
S = zeros(numel(t), 3); % array for storing signal values
for i = 1:numel(t)
s1 = sin(f(1)*t(i));
s2 = sin(f(2)*t(i));
s3 = sin(f(3)*t(i));
S(i, :) = [s1 s2 s3];
end
plot(S)
  댓글 수: 2
marwa mohamed
marwa mohamed 2020년 9월 14일
Thank you sooo much, that works
Ameer Hamza
Ameer Hamza 2020년 9월 14일
I am glad to be of help!

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by