How do I create a multiline plot using values from a table?

25 views (last 30 days)
For example, I have a table:
User Date1 Date2 ....(I have 500+ dates)
{'A'} 1 6 ...
{'B'} 2 8 ...
{'C'} 3 9 ...
{'D'} 4 11 ...
The dates would be located in the x-axis and the values would be in the y-axis. Each user would be a separate line on that graph. I was thinking of converting it to an array and then attempting to plot that but that method does not seem to be working since I have different types of data in this table. What would be the most efficient way of doing this?
Aryan Cross
Aryan Cross on 12 Nov 2020
I have cells in my first column but the rest is double.

Sign in to comment.

Answers (1)

Nora Khaled
Nora Khaled on 12 Nov 2020
If I understand the problem correctly this might help
% creating tabel exampel
col1 = {'A';'B';'C';'D';'E'};
col2 = [1:1:5]';
col3 = randi(5,5,1);
col4 = randi(5,5,1);
col5 = randi(5,5,1);
col6 = randi(5,5,1);
my_table = table(col1,col2,col3,col4,col5,col6);
%plot data for each user
for i=2:1:r
hold on;
Nora Khaled
Nora Khaled on 13 Nov 2020
Ok... try this:
set(gca,'XTick',1:length(my_table.Properties.VariableNames(2:end)),'XTickLabel',my_table.Properties.VariableNames(2:end), 'XTickLabelRotation',45)
Also, change the loop vaiable to start from 1 :
for i=1:1:r
hold on;

Sign in to comment.


Find more on Specifying Target for Graphics Output in Help Center and File Exchange





Community Treasure Hunt

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

Start Hunting!