MATLAB: spilliting an array into n parts and then joining them again forming a histogram

i am new to matlab.
lets say i have an array a = [1:1:1000]
i have to divide this into 50 parts 1-20; 21-40 .... 981-1000.
i am trying to do it this way.
E=1000X
a=[1:E]
n=50
d=E/n
b=[]
for i=0:n
b(i)=a[i:d]
end
but i am unable to get the result
and the second part is i am working is , depending on another result, say if my answer is 3 , the first split array should have a counter and that should be +1, if the answer is 45 the 3rd split array's counter should be + 1 and so on and in the end i have to make a histogram of all the counters.

 Accepted Answer

Change
b(i)=a[i:d]
to
b{i+1} = a(i*d+1:(i+1)*d);
The rules you are trying to establish for the histogram are not clear. Have you considered using hist() or histc() to build the histogram ?

1 Comment

about the histogram: after splitting the array into 50 parts, lets say i work on part 2 of the problem and for about 10000 simulations, and i get 55 as the answer in the first simulation then the column/part which contains 55 i.e, clolumn 3 (containing 41-60) which has a counter increase its value by 1. and so on ; if i get an answer as 999, the last cloumn i.e, 50th should increase its counter by 1 and in the end after all the 10000 simulations i get a histogram of the counter values

Sign in to comment.

More Answers (1)

a=1:1000
out=reshape(a,20,[])
% If you want to put a result in a cell array
res=arrayfun(@(x) out(:,x),1:1000/20,'un',0)

1 Comment

azzi, thanks for the answer, i tried it and i dont understand a word of it :).... its all high end stuff, i will try t read about it and then run it again

Sign in to comment.

Categories

Find more on MATLAB 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!