开发者

Matlab: 3d bar plot over specified axes

开发者 https://www.devze.com 2023-02-15 00:45 出处:网络
Hallo SOers: After searching for a while, the answer still does show up for my question: I have a data file like:

Hallo SOers: After searching for a while, the answer still does show up for my question:

I have a data file like:

x  y     z
10 100   30
10 500   90
10 600   200
30 200   30
90 120   300
90 130   30
90 200   60

In matlab, I want to plot z over (x, y), which are not continuous points. The plot point should be a bar. But plot3() seems do not support 3d bar plot,

and bar3() seems do not allow me to 开发者_运维百科specify my (x,y) column.

So how to get such sparse bar plot?

Many thanks!


You could put the values into a Matrix where each element represents a bar. You set your elements to a value and all other elements to zero.

>> 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)
>> 

I am sure you could make the plot nicer by changing some parameters, but this would be the output.

Matlab: 3d bar plot over specified axes

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号