How I obtain with function bar3 different sizes for each bar in MATLAB?
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Jose Manuel
le 18 Juin 2014
Réponse apportée : Jan Orwat
le 18 Juin 2014
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 commentaires
Réponse acceptée
Jan Orwat
le 18 Juin 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 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Line Plots dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!