How can I divide an interval in intervals with the same length?

Hello,
I have a point cloud and I would like to do a Matlab program, which calculates the mean of values of intervals, which have the same length. I don't know how I can begin that. Please, I need your help.
Maxime

 Accepted Answer

Here's an example of what might lead you to your end goal:
A = 1:64; %vector
B = mean(reshape(A,8,8),1); %mean of intervals 8 long.
Is this what you're looking for? If it's not please provide a small sample of input data/operation/expected output

7 Comments

I have two 4608-by-1 vectors a and b, and the respective intervals are [2.4895e-04; 0.0177] and [0.1981; 8.9363]. I have a point cloud which is linear, when I do plot(b,a,'o'). I would like to calculate the mean of each vector in each intervals to finally plot that with standard deviation.
So, I will have a straight line with the breadth on each point and for the two vectors, which are plot.
Is it more clear?
First, don't accept an answer when the problem isn't _actually_ solved. Second, no it's not clear what you want. Do you want something like errorbar ?
Perhaps you could post a picture of your plot to a file hosting website somewhere so it's a little clearer.
Sorry, I clicked on the wrong touch.
Then, it is like errobar, like the second picture in the matlab help.
You could see the plot here:
http://dl.free.fr/pWNQPggOe
By sorting the data (to group it together) and reshaping you should be able to calculate what you want.
I see. What do you think about that?
I have a 4608x1 vector a and I do
sort(a(a>2e-4 & a<4e-4)) for example and I apply this example for each interval?
Actually: use histc (second output argument) and accumarray to bin-> mean the values directly.

Sign in to comment.

More Answers (2)

Hi,
are you looking for something like this?
start_interval = 0;
end_interval = 10;
intervals = 20;
interval_length = (end_interval - start_interval)/intervals;
x = start_interval + (end_interval-start_interval)*rand(200,1);
y = rand(200,1);
plot(x,y,'*')
hold on
for i=1:intervals
left = start_interval + interval_length*(i-1);
right = start_interval + interval_length*i;
ind = x >= left & x < right;
m_y = mean(y(ind));
line( [left,right],[m_y,m_y], 'Color','r' );
line( [left,left], [-0.5,1.5] ,'Color','black')
end
hold off

4 Comments

Hi,
It is a bit like this, but instead of x and y, I have two 4608-by-1 vectors a and b, and the respective intervals are [2.4895e-04; 0.0177] and [0.1981; 8.9363]. So, how can I plot the point cloud within the mean and the standard deviation like on the errorbar tool? Or without the point cloud?
I think you have to modify my code to this
start_interval = min(a);
end_interval = max(a);
x = a;
y = b;
To show the linearity, I must plot with loglog and I have a warning, which says that negative data ignored.
Then, I think that your code calculate the mean only on the values of y, and I would like to have the mean of x too.
Sorry, but do you know how can I add the standard deviation like the errorbar fonction on the plot?
I am very grateful for your help and I hope there is no problem :D

Sign in to comment.

Probably you need to elaborate a bit more what exactly your problems is?
For this much all I can say is that you can use mean command in matlab for calculating mean of values. Use help mean to get a better insight of it.
Or
You can use this a=1 % this will represent you length of interval
b = zeros(size(X));
for n =1:length(X)-1
b(n) = (X(n)-X(n+1)>a)
end
z =find(b>a) % this will return all index for this is true
and then use something like this mean (X(z));
But for better understanding your problem, you must elaborate your problem.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!