Drawing open polygonial lines

Is it possible to same-color lines be not-connected? Like in this picture: http://i51.tinypic.com/2wns3v8.png
Important part of the problem is that it need to be easy to change coordinates of the lines.
something like:
red=[{(1,1),(3,5),(9,2)},{(5,3),(7,4)}] %%two parts
blue=[{(9,1),(4,3),(3,3),(7,1),(7,9)}] %%one part
draw();
set(red, ....) %%here we change red parts
draw();

回答(1 个)

Yes. Join all of the x values for red with nan where you the want the break to go, and likewise for the y values, and then plot() the line.
Note: {(1,1),(3,5)} means the same thing to MATLAB as {1,1,3,5} does. () is not a vector grouping operator syntax. Also, [{...}] means the same thing as {...} -- an array containing a single cell array is the same thing as the cell array.
The below might work, but I do not have access to my MATLAB to test it:
red(2,:) = [nan,nan];
redx = cell2mat(cellfun(@(V) V(1:2:end), red(:), 'Uniform', 0));
redy = cell2mat(cellfun(@(V) V(2:2:end), red(:), 'Uniform', 0));
plot(redx, redy, 'r');

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by