Pascal to matlab without padarray command

7 vues (au cours des 30 derniers jours)
s
s le 28 Juin 2012
hello, how can I translate this code in matlab? I was planning to create a vector from 1 to 300, make the calculations for w1(n1>0), then increase its size to 600, shift the data and create a mirrorlike copy of it to account for the negative indices... but I got lost here it is the code
begin
l1:=70;
for n1:= 0 to round(l1/2) do
begin
w1[n1]:=cos(n1);
w1[-n1]:=w1[i1,n1];
end;
for n1:=round(l1/2)+1 to 300 do
begin
w1[n1]:=w1[round(l1/2)]*exp(-(n1-round(l1/2)));
w1[-n1]:=w1[n1];
end;
end;
end
thanks

Réponses (1)

Walter Roberson
Walter Roberson le 28 Juin 2012
l1 = 70;
half_l1 = round(l1/2);
for n1 = 0 : half_l1
w1(half_l1 + 1 + n1) = cos(n1);
w1(half_l1 + 1 - n1) = w1(i1, n1 + 1);
end
for n1 = half_l1 + 1 : 300
w1(half_l1 + 1 + n1) = w1(half_l1 + 1 + half_l1) * exp(-(n1-half_l1));
w1(half_l1 + 1 - n1) = w1(half_l1 + 1 + n1);
end

Catégories

En savoir plus sur Get Started with MATLAB dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by