Hi Alessandro,
When you say that you "want to draw a closed ring shape with a single line", we might step-by-step reinterpret this as:
"I want to draw an object that has 2 lines, but only use 1 line"
and then:
"I want to draw one line with an array of points, but I want a program to (somehow) automatically detect one (or more?) of these points to split at, and pretend that I actually drew two lines".
If you were to define your question with actual input data to go with the diagrams you made, I imagine you'd have simply an N-by-2 array of points. From there, I imagine that the answer would be to somehow detect a "special" location in your N points, and then insert a [nan nan] at that location, finally send the result to mpoly2mask.
So probably the reason why this question hasn't gotten an answer yet, is that before anyone tries to answer it (magically knowing which place to split your single array of points without more information will be very tricky), they'd probably want to convince you to change the question definition itself.
For instance, why exactly, must it all be drawn in a single line? It seems in your question that you are defining that you want to draw a closed ring. This type of object is naturally described by 2 lines. It would be much much simpler to make a small (but logical) modification to your program to ask the user to draw 2 lines, rather than to try to guess which part of their drawing was meant to be the inner part and which part of their drawing was meant to be the outer part. For instance in the diagram you provided, there are actually 3 separate self-intersection locations in your line, and it's not clear for a program to choose which one(s) to use.
Making a change to your question instead, you'd basically have:
innerCircle = ...
outerCircle = ...
A = false(2);
A(1,2) = 1;
BW = mpoly2mask({innerCircle outerCircle}, A);
That's just 5 straight-forward lines of code. Any attempt to guess the intended break between inner and outer circle will certainly be much more difficult and complicated.
Hope this answer helps you out,
Sven