1
votes

I am reading a table in MATLAB as follows:

  R = readtable('Recalls_All.csv','Delimiter',',','ReadVariableNames',false,...
'ReadRowNames',false);
  R.Properties.VariableNames = {'Features','R1','R5','R10','R20'};

The first column of this matrix are 'string' data types corresponding to different algorithms and the other 4 columns are numeric. How can I, without using loops, plot the rows as a function of columns.

  • x_axis: columns
  • y-axis: rows which correspond to different algorithms

Obviously plottting is not a difficult task using readtable(). However since there exist 180 rows, I would like a legend() to be created for each plot (algorithm) autmatically.

Cool ideas are appreciated.

2
Aren't the variable names stored as cell? That you can use as a legend afaik.Adriaan
The variables names are only 5. The problem is the rownames and those are the ones I want to created a legend from.yas yasi
Yes, that's what I meant. The algorithm names. Aren't they stored somewhere as a cell?Adriaan
No, they are coming directly from a file. But I think it is possible to have them as a cell. Do you have any idea?yas yasi

2 Answers

2
votes

Here is an option to do it all:

% some arbitrary data:
R = table({'algorithm1' 'algorithm2' 'algorithm3'}.',randi(100,3,1),...
    randi(100,3,1),randi(100,3,1),randi(100,3,1),...
    'VariableNames',{'Features','R1','R5','R10','R20'});
ax = axes; % create axes
plot(ax,table2array(R(:,2:end)).'); % plot data
ax.XTick = 1:width(R); % limit X-axis ticks no. to columns
ax.XTickLabel = R.Properties.VariableNames(2:end); % get columns names
legend(table2cell(R(:,1))); % get algorithm names

and the result:

Plotting a table

and off course you can tweak the plot as you want (lines, marker, limits, etc..)

1
votes
>> A = [1:5] .* [1:10]'    % example matrix
A =

    1    2    3    4    5
    2    4    6    8   10
    3    6    9   12   15
    4    8   12   16   20
    5   10   15   20   25
    6   12   18   24   30
    7   14   21   28   35
    8   16   24   32   40
    9   18   27   36   45
   10   20   30   40   50

>> VariableNames = {'name1', 'name2','name3','name4','name5'};
>> plot(1:size(A,1), A')
>> legend (VariableNames{:})

enter image description here