Plotting index-determined points in a continuous line plot in a different color

1 次查看(过去 30 天)
I am investigating spike detection in audio data. I have 3 vectors of data: t, xp and yp, which I produce a 3D diagram from using plot3. Earlier on in my script, I determine a vector, say 'color2', containing the indexes of points that I would like to plot as blue, with the rest of the data as black. It is easy to produce a 3D plot of un-connected points with the following code:
plot3(fig4,t(color1),xp(color1),yp(insideIndex),'k.'); % Plot points as black dots
plot3(fig4,t(color2),xp(color2),yp(color2),'bo'); % Plot points of interest as blue pluses
This produces the following plot:
However, ideally I would like a single, continuous line of data where blue points are joined by blue lines and black points are joined by black lines, similar to the image below:
What's the simplest way of doing this? Cheers.

回答(1 个)

Saurabh Gupta
Saurabh Gupta 2017-7-31
Generally speaking, line plot functions combine adjoining points, based on the input vectors, into line segments. All you need to do it separate the data for both cases, and arrange the points in each data set in order of succession (as per line plotting requirements). Then, the 'plot3' command should be able to produce the continuous line plots that you require.
I am guessing that you are aware that your current commands use LineSpec as 'k.' and 'bo' which plot points only and not the connecting lines. But I thought I should mention it also just in case.
Hope this helps!
  4 个评论
Tom Andersson
Tom Andersson 2017-8-8
Thank you for the clarification Saurabh - your explanation has made me realise that I wasn't clear enough in my question. I don't want two separate lines of different colors, I want one continuous line comprised of two different colors. I don't think MATLAB supports this functionality, but perhaps there is a workaround?
José-Luis
José-Luis 2017-8-8
I'm afraid it's not going to happen automagically. You will need two lines if you want two different colors.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Specifying Target for Graphics Output 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by