customised x data in matlab plot

조회 수: 1 (최근 30일)
Tino
Tino 2019년 5월 28일
댓글: Tino 2019년 5월 28일
I have an x label ( starting from 0 in the axis - 1000, 2000, 3000, 4000, 50000, 6000)
I want to change the axis to the following starting from 0 in the axis - 2000, 4000, 6000, 8000, 10000, 12000
I have used the following implementation but not working
labels = [0 2000 4000 6000 8000 10000 12000];
disp(plot(X));
set(gca, 'XTick', 1:length(labels));
set(gca, 'XTickLabel', labels);
Can someone help me out with this
Thanks in advance

채택된 답변

Rik
Rik 2019년 5월 28일
The XTick property requires a vector with numeric data, but the XTickLabel property requires a cell array.
labels = [0 2000 4000 6000 8000 10000 12000];
disp(plot(X));
set(gca, 'XTick', 1:numel(labels));%this puts the labels at x=1,2,3,4,5,6,7
set(gca, 'XTickLabel', cellfun(@num2str,num2cell(labels));
  댓글 수: 8
Rik
Rik 2019년 5월 28일
Then you can use this:
labels_real = [0 1000 2000 3000 4000 5000 6000];
labels_fake = [0 2000 4000 6000 8000 10000 12000];
%or just:
%labels_real=0:1000:6000;
%labels_fake=0:2000:12000;
%or even:
%labels_real=0:1000:6000;
%labels_fake=labels_real/2;
disp(plot(X));
set(gca, 'XTick', labels_real);
%this is now optional:
set(gca, 'XTickLabel', cellfun(@num2str,num2cell(labels_fake),'UniformOutput',0);
Tino
Tino 2019년 5월 28일
Thank you Rik

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

추가 답변 (0개)

카테고리

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

태그

제품


릴리스

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by