フィルターのクリア

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 Center および File ExchangeAxis Labels についてさらに検索

タグ

製品


リリース

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by