Pascal to matlab without padarray command

조회 수: 6 (최근 30일)
s
s 2012년 6월 28일
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