MATLAB中的一些数据的三维可视化 [英] 3D visualization of some data in MATLAB

查看:491
本文介绍了MATLAB中的一些数据的三维可视化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我在MATLAB中的数据矩阵:

  a = [43.676289 -79.477386 1 
43.676370 -79.477107 5
43.676517 -79.477375 20
43.676417 -79.477509 8
43.676129 -79.477278 15];

第一列是 Y 轴,第二列是 X 轴,第三列是我的数据。如何绘制条形图,并根据MATLAB中每个数据点的数据值(如曲面图中的 colorbar )调整条的颜色?



我添加了一个示例图,我绘制了另一个数据矩阵。在这个例子中,X,Y和Z是线性的,我可以使用'surf'命令绘制这个图形,没有问题。我需要为上述数据绘制相同的图形,但 XY 轴的单位与 Z 不兼容,这令我困惑。





正如其他评论如果我们仅绘制XY平面,结果如下图所示:

  scatter(a(:,2), a(:,1),'*')



然而,我认为 bar3 可能是更好的选择:

  b = bar3(sort(a(:,1)),Z); 
xticklabels(sort(a(:,2)));
cdata_sz = size(b(1).CData);
z_color = repelem(Z,6,4);
z_color(abs(z_color)< 1)= nan;
z_color = mat2cell(z_color,...
cdata_sz(1),ones(1,size(Z,2))* cdata_sz(2));
set(b,{'CData'},z_color。')
view(-70,30)


This is my data matrix in MATLAB:

a = [43.676289  -79.477386  1
     43.676370  -79.477107  5
     43.676517  -79.477375  20
     43.676417  -79.477509  8
     43.676129  -79.477278  15];

The first column is Y axis, the second column is X axis and the third column is my data. How can I draw a bar graph, and adjust the color of the bars according to the value of data (like colorbar in a surface plot) for each data point in MATLAB?

I added an example graph which I drew for another data matrix. In this example X, Y, and Z were linear and I could draw this graph using 'surf' command with no problem. I need to draw the same graph for mentioned data, but the unit of the XY axis is not compatible with Z, and this confused me.

Just as an additional comment, if we plot only the XY plane, the result looks like the next picture:

scatter(a(:,2),a(:,1),'*')

Moreover, this is a simple example that might be useful to expand it:

z = [5     0     2     0
     0     0     0     0
     0     0     0     0
     0     0     0     0];
[X,Y] = meshgrid(0:1:3);
surf(X,Y,Z)

Thanks

解决方案

Here is something you can do - build Z as a matrix from your data:

a = [43.676289   -79.477386  1
     43.676370   -79.477107  5
     43.676517   -79.477375  20
     43.676417   -79.477509  8
     43.676129   -79.477278  15];
[X,Y] = meshgrid(sort(a(:,2)),sort(a(:,1)));
Z = zeros(size(X));
for k = 1:size(a,1)
    xind = abs(X-a(k,2))<eps;
    yind = abs(Y-a(k,1))<eps;
    Z(xind & yind) = a(k,3);
end

Typing surf(X,Y,Z) will give you this:

However, I think that bar3 might be a better choice:

b = bar3(sort(a(:,1)),Z);
xticklabels(sort(a(:,2)));
cdata_sz = size(b(1).CData);
z_color = repelem(Z,6,4);
z_color(abs(z_color)<1) = nan;
z_color = mat2cell(z_color,...
    cdata_sz(1),ones(1,size(Z,2))*cdata_sz(2));
set(b,{'CData'},z_color.')
view(-70,30)

这篇关于MATLAB中的一些数据的三维可视化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆