yyaxis plot joining start and end points with a straight line

1 view (last 30 days)
Hi All, I am plotting two signals using yyaxis which has the same time span, but while plotting it is joining start and end points of both the signals with a straight line which is kind of strange behaviour. But for some of the channels it is plotting perfectly.
I tried with removing all nan values but no luck. Checked size of both the signals and all are same. I am not able to find any properties that might have been accidently set. Code snippet below,
yyaxis left;
cla(axesHome, 'reset');
plot(axesHome, time, singal_1, 'LineWidth',1.5); grid on;
yyaxis right;
plot(axesHome, time, signal_2, 'LineWidth',1.5); grid on;
Please help.

Accepted Answer

Rik
Rik on 27 Mar 2018
Because I don't have your data I can't check this, but it might be the case that your data is not well-sorted, so plot results in an unexpected straight line. The code below should ensure this is not the case.
yyaxis left;
cla(axesHome, 'reset');
[temp_time,order]=sort(time);
plot(axesHome, temp_time, singal_1(order), 'LineWidth',1.5); grid on;
yyaxis right;
plot(axesHome, temp_time, signal_2(order), 'LineWidth',1.5); grid on;

More Answers (0)

Categories

Find more on Graphics in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!