MATLAB爱好者论坛-LabFans.com

MATLAB爱好者论坛-LabFans.com (https://www.labfans.com/bbs/index.php)
-   资料存档 (https://www.labfans.com/bbs/forumdisplay.php?f=72)
-   -   Matlab:指定轴上的3d条形图 (https://www.labfans.com/bbs/showthread.php?t=26469)

poster 2019-12-14 20:13

Matlab:指定轴上的3d条形图
 
哈罗·索尔斯(Hallo SOers):搜索了一会儿之后,我的问题仍然显示出来了
我有一个数据文件,如:

xyz 10 100 30 10 500 90 10 600 200 30 200 30 90 120 300 90 130 30 90 200 60 在Matlab中,我想将z绘制在(x,y)上,它们不是连续的点。绘图点应为条形图。但是plot3()似乎不支持3D条形图,
和bar3()似乎不允许我指定我的(x,y)列。

那么如何获得这样的稀疏条形图呢?

非常感谢!



[B]回答:[/B]

您可以将值放入一个矩阵,其中每个元素代表一个条形。您将元素设置为值,而所有其他元素设置为零。

>> x = x./10 %I scaled the x and y values down by factor of 10 x = 1 1 1 3 9 9 9 >> y = y./10 y = 10 50 60 20 12 13 20 >> A = zeros(max(x),max(y)); %create Matrix of size 9x20 >> for i = 1:length(x) A(x(i),y(i)) = z(i); %populate the Matrix end >> bar3(A) >> 我相信您可以通过更改一些参数来使图更好,但这将是输出。

[IMG]https://i.stack.imgur.com/vBbOp.jpg[/IMG]



[url=https://stackoverflow.com/questions/5178430]更多&回答...[/url]


所有时间均为北京时间。现在的时间是 03:01

Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.