MATLAB Answers

Beginner's question about data plot

1 view (last 30 days)
Raimund Herberg
Raimund Herberg on 3 Dec 2019
Commented: Raimund Herberg on 3 Dec 2019
0-1-0 Signal.jpg
The data used for this plot is a series of 0's followed by a series of 1's, then back to 0's. I expected to see a 0-1-0 pulse shaped signal starting at around 15 minutes and ending just before 50 minutes, but instead I see a starting and trailing slope. What causes this behavior? The code is as simple as it gets:
figure(1), plot(time,Enable_d)
title('Signal Enabled')
xlabel('Time (min)')

  2 Comments

KALYAN ACHARJYA
KALYAN ACHARJYA on 3 Dec 2019
How you expected to switch from 1 to 0, in plot its connect both data points have you look at stem?
figure(1), stem(time,Enable_d)
title('Signal Enabled')
xlabel('Time (min)')
Raimund Herberg
Raimund Herberg on 3 Dec 2019
0-1-0 Signal-v2.jpg
stem and stairs show similar behavior - a pulse between 40 and 50 minutes. But the corresponding data is '0' from 0 minutes to 15 minutes, '1' from 15 minutes to 50 minutes, then again '0' from 50 minutes to 80 minutes.

Sign in to comment.

Answers (4)

the cyclist
the cyclist on 3 Dec 2019
Try this instead
plot(time,Enable_d,'.','MarkerSize',32)
This code will plot individual points, without a connecting line.

  0 Comments

Sign in to comment.


Raimund Herberg
Raimund Herberg on 3 Dec 2019
0-1-0 Signal-v3.jpg
We are not quite there - still a '1' signal gap between 15 minutes and 40 minutes

  1 Comment

the cyclist
the cyclist on 3 Dec 2019
How do you expect MATLAB to "know" how to fill in the gap from 15 to 40? How can it know you want it to be 1 right after Time = 15, rather than 0, or 0.5, or 0.73245?
The answer is -- MATLAB can't know what to plot there unless to program it to.

Sign in to comment.


Raimund Herberg
Raimund Herberg on 3 Dec 2019
The data is only 0's and 1's, binary, nothing else.
'0's from 1 minutes to 15 minutes, '1's from 15 minutes to 50 minutes, then again '0's from 50 minutes to 80 minutes.

  4 Comments

Show 1 older comment
Raimund Herberg
Raimund Herberg on 3 Dec 2019
You are 100% correct, there are gaps in the data, see the attached excel file.
I was recently assigned to check the sizeable data collection related to a mile-long script and tripped over a few things that were all along assumed to be ok. I extracted data that I was suspicious of and created with it the simple plot depicted at the beginning of this trail.
To my bad I did not compare data and the specific timeline side by side. Instead i just looked at the data and could not understand why the plot function created a slope between 15 minutes and 40 minutes. Beginner's mistake, not to be repeated. Your suggested solution "plot(time,Enable_d,'.','MarkerSize',32)" is right on. Many thanks!!!
And this interaction also taught me a lot about the plot function.
Image Analyst
Image Analyst on 3 Dec 2019
Did stairs() like in my answer not work? Did you even try it?
Raimund Herberg
Raimund Herberg on 3 Dec 2019
Yes, I tried it as well, works beautifully!
Thanks a lot for your support.

Sign in to comment.


Image Analyst
Image Analyst on 3 Dec 2019
To get a plot with sharp, not sloping, edges, use stairs() or bar().

  0 Comments

Sign in to comment.

Sign in to answer this question.

Products


Release

R2018b