필터 지우기
필터 지우기

Logarithmic scale with a different base

조회 수: 49 (최근 30일)
Ido Gross
Ido Gross 2020년 8월 13일
답변: Joshua Carmichael 2021년 8월 13일
Hi,
I am trying to plot a function using logaritmic scale on the x axis, with base 2.
my code is:
N = 1:10000;
M = 61;
L = N-M+1;
ova_complex = ((N.*(log2(N)+1))./(N-M+1));
figure
stem(log2(N),ova_complex)
xlim([6 14])
the graph im getting is good, but i want to show only the integer values on the x axis(i.e. 6,7,8,9)
is there a way to do that?
thanks

답변 (4개)

Star Strider
Star Strider 2020년 8월 13일
Try this:
N = 1:10000;
M = 61;
L = N-M+1;
ova_complex = ((N.*(log2(N)+1))./(N-M+1));
figure
stem(log2(N),ova_complex)
xlim([6 14])
xt = get(gca, 'XTick'); % ADD THIS LINE
xtl = fix(min(xt)):fix(max(xt)); % ADD THIS LINE
set(gca, 'XTick',xtl) % ADD THIS LINE
That should produce integer ticks and integer tick labels.
.

hosein Javan
hosein Javan 2020년 8월 13일
add the following after plot
ax = gca; % current axe
ax.XTick = 6:14;

Walter Roberson
Walter Roberson 2020년 8월 13일
log2(x) = log(x) *log(2)
log(2) is a uniform scaling and since plots are scaled to fit available space, becomes irrelevant.
So you get the same shape if you use semilogx. And you can lie with the labels if you want. However if you are using datatips you need your approach (unless you program them to lie)
You can use xticks() to choose integer tick locations.

Joshua Carmichael
Joshua Carmichael 2021년 8월 13일
For a natural log base, try:
logspace(0, log10(exp(1)),100)
To generate a spaced set of 100 samples that start at one and terminate at e^(1).

카테고리

Help CenterFile Exchange에서 Axis Labels에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by