Decimal numbers problem on plotting

조회 수: 1 (최근 30일)
Ulrich Achas
Ulrich Achas 2021년 5월 11일
댓글: DGM 2021년 5월 11일
I am plotting a graph about a parameter that changes according to years on MATLAB. But on the years label, decimal numbers are seen. How can I make them unseen?

답변 (1개)

DGM
DGM 2021년 5월 11일
편집: DGM 2021년 5월 11일
Consider:
% make a simple plot that reproduces the fractional year ticks
x = 2016:0.5:2020
plot(x,x)
% get rid of tick labels for non-integer years
xtl = get(gca,'xticklabel')
mask = cellfun(@(x)mod(str2num(x),1)>eps,xtl);
xtl(mask) = {''}
set(gca,'xticklabel',xtl)
There are probably other ways to do this, but this is what I came up with off the top of my head.
  댓글 수: 2
Ulrich Achas
Ulrich Achas 2021년 5월 11일
thank you so much but as a beginner, it's a little bit complicated for me.
DGM
DGM 2021년 5월 11일
You might also be able to get away with something like this:
x = 2016:0.5:2020
plot(x,x)
xt = get(gca,'xtick')
set(gca,'xtick',xt(mod(xt,1)==0))
though it will also remove the half-year tick marks as well

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Grid Lines, Tick Values, and Labels에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by