How to draw a histogram on FreeMat?
Does the HIST function work for drawing a histogram?
Thanks!
function bar(x,y)
xspacing = x(2)-x(1); % assuming monotonic x vector
barwidth = xspacing*0.5;
lx = length(x);
rightbarx = zeros(lx,2);
leftbarx = zeros(lx,2);
topbarx = zeros(lx,2);
rightbary = zeros(lx,2);
leftbary = zeros(lx,2);
topbary = zeros(lx,2);
for i = 1:lx;
leftbarx(i,:) = [(x(i)-0.5*barwidth) (x(i)-0.5*barwidth)];
rightbarx(i,:) = [(x(i)+0.5*barwidth) (x(i)+0.5*barwidth)];
topbarx(i,:) = [(x(i)-0.5*barwidth) (x(i)+0.5*barwidth)];
leftbary(i,:) = [0 y(i)];
rightbary(i,:) = [0 y(i)];
topbary(i,:) = [y(i) y(i)];
end
figure(); hold on;
for i = 1:lx
plot(leftbarx(i,:),leftbary(i,:),'-k',rightbarx(i,:),rightbary(i,:),'-k',topbarx(i,:),topbary(i,:),'-k')
end
--
You received this message because you are subscribed to the Google Groups "freemat-devel" group.
To post to this group, send email to freema...@googlegroups.com.
To unsubscribe from this group, send email to freemat-deve...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/freemat-devel?hl=en.
In FreeMat hist uses patch, by the way. Also, there is bar
implementation in the hist function (borrowed from octave):
function h=bar( x, y, width, varargin )
x=x(:);
y=y(:);
if (length(x) ~= length(y))
error('cannot handle this case');
end
df = width*diff( x )/2;
df(end+1) = df(end);
x_r=x(1:end)-df;
x_l=x(1:end)+df;
n = length(x);
vertices = [ x_r zeros(size(x_r)) ones(size(x_r)) ;...
x_r y ones(size(x_r)) ;...
x_l y ones(size(x_r)) ;...
x_l zeros(size(x_l)) ones(size(x_r))];
ind=(1:n)';
faces = [ind ind+n ind+2*n ind+3*n];
if ~ishold
clf
end
h=patch('Faces',faces,'Vertices',vertices,'FaceColor',[0 0 1]);
Thanks,
Eugene