Search All of the Math Forum:
Views expressed in these public forums are not endorsed by
Drexel University or The Math Forum.
|
|
Jonas
Posts:
1
Registered:
11/7/09
|
|
Histogram
Posted:
Nov 7, 2009 1:50 PM
|
|
Does anybody have a better solution for the code below? The x- and edge-vectors has a size of 5000 elements in my problem, and the sum of k-vector is equal to the length of the x- and edge-vectors, the code allocates a lot of memory unnecessarily.
Similar problem x = (1:1:11)'; u = [2 3.5 4 5 6 5 4 4 3 2 1]'; umin = min(u); umax = max(u); edge = linspace(umin,umax,numel(x))'; [k bin]=histc(u,edge);
u1 = zeros(length(k),max(k)); edge = flipud(edge); for i=1:length(k) u1(i,1:k(i))=edge(i); end [m,n] = size(u1); for i=1:m u2((i*n+1):((i+1)*n)) = u1(i,:); end ind1=find(u2==0); u2(ind1)=[]; subplot(2,1,1); plot(x,u) subplot(2,1,2); plot(x,u2)
|
|
|
|