I have following Matlab code:
xC= zeros(1,n);
yC= zeros(1,n);
for i=1:(b/delta);
xC(i) = -a/2;
yC(i) = b-(i-1/2)*delta;
end;
for i=1:(a/delta);
xC(i+b/delta) = -a/2+(i-1/2)*delta;
yC(i+b/delta) = 0;
end;
for i=1:(b/delta);
xC(i+b/delta+a/delta) = a/2-(1/2)*delta;
yC(i+b/delta+a/delta) = (i-1/2)*delta;
end;
Since i'm new to mathematica can anyone help me convert this to mathematica code.
explanation: I am trying to create a matrices 1x300 (n=300).
creating empty matrices with this:
xC= zeros(1,n);
yC= zeros(1,n);
First For loop is filling first 50 elements of matrices with values -a/2 and b-(i-1/2)*delta
. Second loop is filling the next 200 elements of matrices with values -a/2+(i-1/2)*delta and 0
and the third loop is filling last 50 elements with a/2-(1/2)*delta and (i-1/2)*delta
.
What i have tried with mathematica is this:
bdelta = b/delta
adelta = a/delta
xC = Table[0, {i, n}]
yC = Table[0, {i, n}];
xC = Table[-a/2, {i, bdelta}];
yC = Table[b - (i - 1/2)*delta, {i, bdelta}];
xC = Table[-a/2 + (i - 1/2)*delta, {i, bdelta + 1, adelta + bdelta}];
yC = Table[0, {i, bdelta + 1, bdelta + adelta}];
xC = Table[a/2 - (1/2)*delta, {i, bdelta + adelta + 1, n}];
yC = Table[(i - 1/2)*delta, {i, bdelta + adelta + 1, n}];
since it's not working and i have very little experience with mathematica and its syntax i would really need some help with this.
xC = PadRight[ConstantArray[-a/2, Floor[b/delta]], n];
andyC = PadRight[b - (Range[b/delta] - 1/2) delta, n];
. In the second for loop you writeyC(i+b/delta) = 0;
but these are already equal to0
aren't they?! $\endgroup$ – Coolwater Mar 14 '18 at 12:18zeros(1,n)
is obvious. $\endgroup$ – Kuba♦ Mar 14 '18 at 12:38