How to plot line with different line style part way through? | MATLAB | Forum

Avatar

Please consider registering
Guest

sp_LogInOut Log In sp_Registration Register

Register | Lost password?
Advanced Search

— Forum Scope —






— Match —





— Forum Options —





Minimum search word length is 3 characters - maximum search word length is 84 characters

sp_Feed sp_TopicIcon
How to plot line with different line style part way through?
No permission to create posts
October 18, 2015
1:46 pm
Avatar
moballa
New Member
Members
Forum Posts: 4
Member Since:
October 18, 2015
sp_UserOfflineSmall Offline

Hello,

I have a few devices sending 3 variables to thingspeak every 30 minutes... device id, temperature, and mode.

I need some help making one graph to display the following:

1) a separate line plotted on the same graph for each deviceID
2) for each line plotted, I would like the line style to change from a solid linestyle when mode is 1 to a dashed linestyle when mode is 0?
3) y axis should represent temperature and x axis should represent the timestamp

I'm new to thingspeak and matlab...the best I have been able to achieve so far is one line on a graph but it has all temperatures and mode from all devices...I haven't been able to separate the lines by deviceID and have no clue if matlab can plot a line using different linestyles *partway* through the line.

Any gurus out there that can point me in the right direction?
Thanks,
Marco

October 19, 2015
8:38 am
Avatar
hans

MathWorks
Members
Forum Posts: 4
Member Since:
January 19, 2011
sp_UserOfflineSmall Offline

moballa,

It is possible to plot multiple lines on a single graph in MATLAB using the 'plot' function:

http://www.mathworks.com/help/matlab/ref/plot.html

According to the documentation, you would provide your data to the function as a column vector, or matrix, depending on the number of lines to plot.

Lines can be assigned a line style or LineSpec. At this time, it does not appear possible for segments between points to be different LineSpecs. However, it is possible to break the data down into more line segments and assign LineSpecs to each line segment. See the following example in the documentation:

http://www.mathworks.com/help/matlab/ref/plot.html?searchHighlight=plot#btzpndl-1

October 19, 2015
10:29 am
Avatar
Rob Purser
Natick, MA

MathWorks
Members
Forum Posts: 47
Member Since:
August 22, 2015
sp_UserOfflineSmall Offline

Hi,

Plotting is a huge subject in MATLAB: See the doc for the plot command here:
http://www.mathworks.com/help/matlab/ref/plot.html

There are lots of ways to do this, but here's something to get you started:
% Generate some data
d = table;
d.timestamp = (datetime('now') - minutes(240):minutes(30):datetime('now'))';
d.temperature = [23;45;56;24;44;56;23;43;55];
d.id = [1;2;3;1;2;3;1;2;3];
d.mode = [1;1;1;1;1;1;0;0;0];
d

% Plot by sensor ID
plot(d.timestamp(d.id == 1),d.temperature(d.id == 1),...
d.timestamp(d.id == 2),d.temperature(d.id == 2),...
d.timestamp(d.id == 3),d.temperature(d.id == 3))

However, it doesn't solve your "dotted when mode is 1" request. You can do this, but it'll take some more work. You'll need to plot the non dotted and dotted separately. So, you'll have 6 lines in your plot.

-Rob

Senior Development Manager for IoT and Hardware Interfacing for MATLAB at MathWorks.  Visit ThingSpeak.com to explore the IoT Analytic platform that speaks MATLAB made for engineers and scientists.  You can collect, analyze, and act in 5 minutes or less!

Forum Timezone: America/New_York

Most Users Ever Online: 114

Currently Online: samdavies
20 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

rw950431: 261

Vinod: 196

piajola: 85

turgo: 70

vespapierre: 63

Adarsh_Murthy: 62

Member Stats:

Guest Posters: 1

Members: 5703

Moderators: 0

Admins: 2

Forum Stats:

Groups: 4

Forums: 17

Topics: 1313

Posts: 4565

Newest Members:

Lakshmanaprakash S B, bettetj60, ronnievw3, bessiesj18, Pavan kumar, Williampup

Administrators: Hans: 387, lee: 457