How I obtain with function bar3 different sizes for each bar in MATLAB?
3 views (last 30 days)
Show older comments
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 Comments
Accepted Answer
Jan Orwat
on 18 Jun 2014
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 Comments
More Answers (0)
See Also
Categories
Find more on Line Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!