Changing numbers near X-axis when plotting

6 ビュー (過去 30 日間)
Andrey
Andrey 2014 年 6 月 14 日
編集済み: Star Strider 2014 年 6 月 14 日
Hi, I import some computation results (single dimension arrays) to Matlab and trying to plot them. However I don't want X-axis labels to be shown as array indexes, I need them to be shown as [Array index]*some_number.
Those computations are are obtained from a difference scheme (uniform grid), for example:
I have X-segment [0,10] and 101 points in my scheme (covering the whole segment with a step 0.1), so as a result I get an array res_1,res_2,...res_99,res_101.
I read it via dlmread(res) and plot, thus getting X-axis labels: 1,2,...,99,101.
But I'd like to have X-axis labels to be shown as: 0,0.1,...,9.9,10.
It seems I should include multiplication of each number on X-axis when drawing X-axis labels (multiplying by step of the grid, 0.1 in current example), but I can't figure how to do this.
Thanks.

採用された回答

Star Strider
Star Strider 2014 年 6 月 14 日
編集済み: Star Strider 2014 年 6 月 14 日
This works!
For a single plot:
figure(2)
plot(V)
xtk = get(gca, 'XTick') % Get 'XTick' values
xtklbl = xtk * 0.1; % Multiply by ‘0.1’
set(gca, 'XTick', xtk, 'XTickLabel',xtklbl) % Replace 'XTickLabel' values
grid
xlabel('X-Axis Indices x 0.1')
axis([0 100 ylim])
For subplots:
V = randi(25, 1, 101); % Create data
figure(1)
subplot(2,1,1) % Plot ‘V’ using indices
plot(V)
grid
xlabel('X-Axis Indices')
axis([0 100 ylim])
hsp2 = subplot(2,1,2) % Plot ‘V’ using indices, then change them
plot(V)
xtk = get(hsp2, 'XTick') % Get 'XTick' values
xtklbl = xtk * 0.1; % Multiply by ‘0.1’
set(hsp2, 'XTick', xtk, 'XTickLabel',xtklbl) % Replace 'XTickLabel' values
grid
xlabel('X-Axis Indices x 0.1')
axis([0 100 ylim])

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeAxis Labels についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by