Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.matlab

Topic: Histogram
Replies: 2   Last Post: Nov 8, 2009 4:35 AM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Jonas

Posts: 1
Registered: 11/7/09
Histogram
Posted: Nov 7, 2009 1:50 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

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)


Date Subject Author
11/7/09
Read Histogram
Jonas
11/8/09
Read Re: Histogram
Bruno Luong
11/8/09
Read Re: Histogram
Bruno Luong

Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2009. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Goodwin College of Professional Studies.