简体   繁体   English

我对Matlab数字有疑问。 我在Matlab中使用bar3函数并想调整轴

[英]I have a questions regarding matlab figures. I use bar3 function in matlab and want to adjust my axes

I have a 2d matrix called myval. 我有一个称为myval的二维矩阵。 Its size is 21x11. 尺寸为21x11。

What I want to do is plot only the first 11 rows and all columns ie 11x11. 我想做的是仅绘制前11行和所有列,即11x11。 So I use a bar3 function in matlab to do this which gives me a good plot. 因此,我在matlab中使用bar3函数来执行此操作,这给了我一个很好的绘图。

Now the z axis is the actual value stored in myval matrix. 现在,z轴是存储在myval矩阵中的实际值。 But it so happens that I want the x and y axis values (which represent the corresponding row and column) to start at 0 instead. 但是碰巧我希望x和y轴值(代表相应的行和列)从0开始。 That is value of (1,1) will be (0,0) and value at (1,2) will be (0,1). 即(1,1)的值为(0,0),(1,2)的值为(0,1)。 I do not want to change the actual value in the myval matrix. 我不想更改myval矩阵中的实际值。 I just want to shift the axis. 我只想移动轴。 this is my actual code 这是我的实际代码

     bar3(myval(1:t,:));
     xlim([0 p]); 
     ylim([0 t]);
     zlim([0 1); 
     set(gca,'fontsize',16); 
     set(gca,'XTick',(0:2:p)); 
     set(gca,'YTick',0:2:t); 
     set(gca,'ZTick',0:1);

You need to give bar3 both an x and Y input then the columns will appear where you want them. 您需要同时给bar3输入x和Y,然后这些列将出现在您想要的位置。

x = 0:10;
Y = myval(1:t,:);
bar3(x,Y)

Or, to controll both the x and y axis, you can use: 或者,要控制x和y轴,可以使用:

x = 0:10;
bar3(Y)
set(gca,'YTickLabel', x)
set(gca,'XTickLabel', x)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM