How I obtain with function bar3 different sizes for each bar in MATLAB?
4 次查看(过去 30 天)
显示 更早的评论
Hi all,
I'm writing to inquire about the doubt that I have written for the title of the question:
%----------------------------
values = [1.0 0.6 0.1; 0.0 1.0 0.3; 0.9 0.4 1.0];
h = bar3(values);
shading interp
for i = 1:length(h)
% Get the ZData matrix of the current group
zdata = get(h(i),'Zdata');
set(h(i),'Cdata',zdata)
end
set(h,'EdgeColor','k')
view(-61, 68);
colormap cool
colorbar
%----------------------------
I want to obtain different sizes for each bar that the sizes are function of variable "values". My aim is also to vary the size of each bar according to the Z value, which is between 0 and 1. When I say "size" I mean the X and Y dimensions of the square, the area of the bar in a top view
Thank you very much, José Manuel
0 个评论
采纳的回答
Jan Orwat
2014-6-18
Hello José,
I hope I've understood you correctly. Do you want bars to be cubes which edges are given by array 'values'? If so, I think it is possible to manipulate XData and YData of the bars. Check out this code below (I've edited yours). With a few changes to it, I think you will get what you want.
values = [1.0 0.6 0.1; 0.0 1.0 0.3; 0.9 0.4 1.0];
h = bar3(values);
shading interp
for i = 1:length(h)
% Get the ZData matrix of the current group
zdata = get(h(i),'Zdata');
set(h(i),'Cdata',zdata);
% Get the YData and the XData to manipulate it
xdata = get(h(i),'XData');
ydata = get(h(i),'YData');
xmat = [nan -1 1 nan;
-1 -1 1 1;
-1 -1 1 1;
nan -1 1 nan;
nan -1 1 nan;
nan nan nan nan];
ymat = [nan -1 -1 nan;
-1 -1 -1 -1;
1 1 1 1;
nan 1 1 nan;
nan -1 -1 nan;
nan nan nan nan];
% Create new YData and new XData
% manipulate width of bar3 columns
xdata=xdata-.5*kron(1-values(:,i),xmat);
ydata=ydata-.5*kron(1-values(:,i),ymat);
set(h(i),'XData',xdata,'YData',ydata);
end
set(h,'EdgeColor','k')
view(-61, 68);
colormap cool
colorbar
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Line Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!