Custom x-axis values in a matlab plot

前端 未结 3 1641
没有蜡笔的小新
没有蜡笔的小新 2021-01-17 16:38

Currently when I plot a 9 by 6 array, the x-axis of the figure is just 1, 2, 3 up to 9. The Y-axis shows the correct values.

Instead of 1 to 9 I would like the x-axi

3条回答
  •  梦谈多话
    2021-01-17 17:13

    You should be using xTickLabel instead of XTick.

    MATLAB plots every column as a seperate curve. So, that means you have 6 curves and 9 data points for each curve. x-axis data is 1-9 because you did not provide any data for MATLAB to plot with.

    Furthermore, you probably want the wrong thing. Doing this will give you equal spacing. It will just replace 1-9 with your array. Since your x-axis data is not equally spaced, it will be weird.

    You may want to do it like this:

    xdat = [100 200 400 1000 2000 5000 10000 20000 50000];
    ydat = rand(9,6); % Your y-axis data
    plot(xdat, ydat)
    

提交回复
热议问题