I started learning a little Matlab a couple days ago.
I wanted to plot a Dirac-comb-like approximation, so given that I knew some functional programming, and that I have been told "you shouldn't need for loops in Matlab", I ended up with this:
M = 50
dx = 0.1
r = 20
x = -r/dx:r/dx
y = arrayfun(@(k) dx .* sum(exp(-2j * pi * dx * k * (-M:dx:M))), x)
But I feel arrayfun isn't a good way to do this -- it just feels awkward/overkill in Matlab.
Or maybe it's just me, I don't know.
Is there a better way to plotting this graph without resorting to arrayfun, or is this the best way?