开发者

Matlab - mark a particular value on x-axis

I would lik开发者_Go百科e to mark a specific value, say 1.2345 on the x-axis, perhaps emphasize it with a bigger dot or a circle or something similar. How do I do this?


The answer to this depends on what you're plotting. If you're plotting a function you could do:

>> fplot(@sin, [0 2])
>> hold on
>> plot(1.2345, sin(1.2345), 'ro')

Matlab - mark a particular value on x-axis

If you're plotting a vector, then use INTERP1 to interpolate the data to your target x value:

>> x = 0:.1:2;
>> y = sin(x);
>> figure
>> plot(x, y, '.-')
>> yi = interp1(x, y, 1.2345)

yi =

         0.942913175277465

>> hold on
>> plot(1.2345, yi, 'ro')

Matlab - mark a particular value on x-axis


One way is to set the XTick and XTickLabel properties of the axes.

set(gca, 'XTick', [0 1 1.2345 2]);

You might also want to draw a vertical line:

line(x0*[1 1], get(gca,'YLim'))

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜