0

I have a matrix for example A=rand(60,60). I want to set the x-axis and y-axis value with step size: 1:2:119 in 3d bar (matlab bar3). I already tried to make it but it doesn't work for large matrix. Note, y-axis is perfect but x-axis is not, it shows from 1 to 60. For example:

Z = rand(60,60);[r,c] = size(Z);
Y = 1:2:119; % y-axis value
X = 1:2:119;   % x-axis value
bar3(Y,Z); set(gca,'XTick', X)

1 Answers1

0

See: xlim and ylim

Z = rand(60,60);
[r,c] = size(Z);
Y = 1:2:119; % y-axis value
X = 1:2:119; % x-axis value
bar3(Y,Z);

xlim([X(1), X(end)]);
set(gca,'XTick', X)

ylim([Y(1), Y(end)]);
set(gca,'YTick', Y)

Sample Plot

The ticks are super crowded but I'm just going with what you specified in your example.

sco1
  • 12,154
  • 5
  • 26
  • 48
  • Thank you so much for your nice feedback. Here, Y-axis value is perfect but the X-axis value doesn't corresponds exactly to bar and It's too crowded. Can I make it exactly like y-axis? I am trying but .... – Delwar Bhuiyan May 26 '15 at 21:43
  • @DelwarBhuiyan The length of the X-axis scale is dependent on the size of your data array. From the documentation for [`bar3`](http://www.mathworks.com/help/matlab/ref/bar3.html): `When Y is a matrix, the x-axis scale ranges from 1 to size(Y,1) and the elements in each row are grouped together.` – sco1 May 27 '15 at 02:20
  • Thanks a lot for your nice reply. But one question regarding this topic. If I make it for a small matrix, for exam: bar3(rand(15,15)), then x-axis value and y-axis value shows perfect but it doesn't works for large matrix, Do you have some idea why??? I have added the code: ...figure; bar3(rand(15,15)) x = linspace(1,119,15); y = linspace(1,119,15); set(gca,'XTickLabel',x) set(gca,'YTickLabel',y) – Delwar Bhuiyan May 27 '15 at 21:37
  • Please [read the documentation](http://www.mathworks.com/help/matlab/ref/bar3.html). `bar3(Y)` is not the same as `bar3(x, Y)` from your original question. – sco1 May 28 '15 at 11:51