Pascal to matlab without padarray command

7 次查看(过去 30 天)
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

回答(1 个)

Walter Roberson
Walter Roberson 2012-6-28
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

类别

Help CenterFile Exchange 中查找有关 Get Started with MATLAB 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by