Search code examples
matlabplotlogarithm

How to write in a logarithmic plot a text in each decade in Matlab


I need to write a different number in each decade, in the bottom or top of my logarithmic plot.

I have these numbers in an array N. There is a way to automate the process without write a for loop for each decade?

In each decade there are 9 numbers, if I have two or three decades, how can write:

for i = 1:18
   text(x(i), y, num2str(N(i)));
end

where, y never change, N(i) are my numbers, and x(i) their position that I'm looking for.

This is an example of my plots I would like put in the orange box (or in the top) the number of black dots.


Solution

  • EDIT: I might have misunderstood your question. One interpretation is of using xticks (explained below). The other is of placing text.

    If all you wanted to do is place text at different locations, it's quite simple given that text also accepts vectors.

    x = 0:1:5;
    y = x;
    plot(x,y);
    text(x+0.25,0.5*ones(6,1),{'One','Two','Three','Four','Five','Six'})
    

    yields:

    enter image description here


    Unless you specifically want to position your labels, I would suggest that you use xticks.

    For e.g.:

    y = 0:1:5;
    x = exp(-y.^2);
    semilogx(x,y);
    set(gca,'XTickLabel',{'One','Two','Three','Four','Five','Six'})
    

    Gives: enter image description here