Pascal to matlab without padarray command

8 Ansichten (letzte 30 Tage)
s
s am 28 Jun. 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

Antworten (1)

Walter Roberson
Walter Roberson am 28 Jun. 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

Kategorien

Mehr zu Get Started with MATLAB 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