Filter löschen
Filter löschen

Save the output of a for loop

3 Ansichten (letzte 30 Tage)
marwa mohamed
marwa mohamed am 10 Sep. 2020
Kommentiert: Ameer Hamza am 14 Sep. 2020
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 Kommentar
KSSV
KSSV am 10 Sep. 2020
Show us the code....so that we can help you.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Ameer Hamza
Ameer Hamza am 10 Sep. 2020
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 Kommentare
marwa mohamed
marwa mohamed am 14 Sep. 2020
Thank you sooo much, that works
Ameer Hamza
Ameer Hamza am 14 Sep. 2020
I am glad to be of help!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by