this is a newbie question. I would like to create an image that intensity obey to the following function g() :
$$ g(x,y) = \begin{cases} -10, & x \in [-50, -10) \\ x, & x \in [-10, 10) \\ 10, & x \in [10, 50] \end{cases} $$
for $y = 0$ to $100$
Here what I have done so far :
I = zeros(10,10)
I(7:10,:) = 10
I(0:4,:) = -10
imwrite(I,'g.jpeg')
But I don't know how to do : g(x,y)=x ?? any help is a welcome
Note that I've used 101 places in the vector $v$ so that my indexing and your formula match nicely. There are also no loops in this program, which will make it much more efficient than matlab code with loops (or at least that's a general principle to live by; in this case, the code's so short it's probably moot.)
Here's an alternative, more "matlab-esque" version
And here's one last version, in a rather terser matlab style: