Filter löschen
Filter löschen

How can I add values to an empty vector from a for loop?

19 Ansichten (letzte 30 Tage)
Penglu Yang
Penglu Yang am 3 Okt. 2016
Kommentiert: Stephen23 am 3 Okt. 2016
y=0;
for l=1:5
y = y+(4.*l*(1/20).^2.*sin(pi*(1/20))*sin(pi*(1/20)))./(pi^2.*(l.^2-(1/20)^2).*(l.^2-(1/20)^2));
disp(y);
end

Antworten (1)

Damien
Damien am 3 Okt. 2016
Hello Penglu,
I'm not sure of what you want to do exactly but you can try this code:
y=0;
for l=1:5
y(l) = y(1)+(4.*l*(1/20).^2.*sin(pi*(1/20))*sin(pi*(1/20)))./(pi^2.*(l.^2-(1/20)^2).*(l.^2-(1/20)^2));
end
disp(y);
More generally use this:
for i = 1:5
y(i)=2*i;
end

Kategorien

Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by