Matlab - Plot a Vector Using Different Line Style

Matlab - Plot a Vector Using Different Line Style
$\begingroup$

I have an array where the first column is the data I want to plot and the second column contains either 1 or -1 to indicate stability. I want to plot the portions of the data marked as '1' with a dashed line, but the rest with a solid line. How do I do this without ending up with the two lines being disconnected? Is there a neat way?

$\endgroup$

1 Answer

$\begingroup$

First extract to vectors, the ones associated with -1, and 1 with :

 dashed = your_Vector(find(your_Vector(:, 2) == 1))
 solid  = your_Vector(find(your_Vector(:, 2) == -1 ))

and then plot as you wish.

$\endgroup$
3

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Sarah Jenkins
Author

Sarah Jenkins

Sarah Jenkins is a veteran tech journalist with over 12 years of experience covering artificial intelligence, mobile innovations, and digital ethics. Her insights have appeared in leading technology publications worldwide.