Matlab as a multi-line chart in Mathematica

So, I have a matrix of values, since the rows correspond to datasets, and I want to build each of them using ListPlot, but I want to have a different x axis than the index. In Matlab, I would:

x = 0:4;

ys = [10 20 40 80 160; 
      20 40 80 160 320; 
      30 60 120 240 480]';

plot(x,ys)

and this will give three rows with x values ​​0-4, and the y values ​​will be each column.

The closest I can find in Mathematica

x = Range[0,4];

ys = {{10, 20, 40, 80, 160},
      {20, 40, 80, 160, 320},
      {30, 60, 120, 240, 480}};

ListPlot[Transpose[{x,#}]& /@ ys]

Mathematica graphics

Is it correct? It seems a little cryptic. Hoping there is a feature or option that I am missing.

+5
source share
1 answer

In your particular case, since the points are equidistant, you can use

ListPlot[ys, DataRange -> x[[{1,-1}]]]

Hope this is less mysterious. Of course, you can also use range values ​​directly:

ListPlot[ys, DataRange -> {0, 4}]
+5

All Articles