I have been reading the MATLAB questions in Stack Overflow for a few weeks, and here was a really good question that came through.
With two vectors, x and y, bin the x values as if with a histogram. Then take the corresponding y values in each bin and take the mean. This uses HISTC and indexing. Mostly this is applying skills from earlier videos.
I really like the Stack Overflow community, and am glad to see the MATLAB questions are being discussed there. Do you have any favorite communities, apart from MATLAB Central, that you like to use?
3 years ago we built a community for French MATLAB users here: http://www.developpez.net/forums/f148/environnements-developpement/matlab/
It is like the MATLAB Central except 5 of us can moderate the forum (check spelling, no SMS message, use of HTML markup to insert code or error messages…). It is currently divided in 4 parts : MATLAB , GUI, IMAGE and Signal Processing. For each part we promote the new releases of MATLAB and of course your blogs!
There are very often ways in MATLAB to accomplish tasks in fewer commands. It is mostly a matter of taste as to which to use.
I tend to go for things that are easily read and understood by the most people. I needed to look up the doc on ACCUMARRAY to understand the above code. So, I suspect many people, myself included, would take longer to understand the shorter code. It is all trade-offs, and knowing several ways of doing something is great.
Good find, I will have to add that to my bag of MATLAB tricks.
Hi Doug, thanks for the explanation. I have a question related to your post. After getting the corresponding frequency of occurrence of y in each of the bins on the x-axis, I wanted to plot the data as a histogram plot. I want to come up with a histogram plot that looks like the ones on the following figure. I am not sure how to do it though. Any suggestion will be very helpful.
3 years ago we built a community for French MATLAB users here:
http://www.developpez.net/forums/f148/environnements-developpement/matlab/
It is like the MATLAB Central except 5 of us can moderate the forum (check spelling, no SMS message, use of HTML markup to insert code or error messages…). It is currently divided in 4 parts : MATLAB , GUI, IMAGE and Signal Processing. For each part we promote the new releases of MATLAB and of course your blogs!
I just checked out Stack Overflow last night, and it looks like a pretty cool community. I think I may start getting active over there.
Thanks for pointing it out!
Ken
The last loop could’ve been done simpler:
binMean = accumarray(whichBin, y, [], @mean)
Ilya,
There are very often ways in MATLAB to accomplish tasks in fewer commands. It is mostly a matter of taste as to which to use.
I tend to go for things that are easily read and understood by the most people. I needed to look up the doc on ACCUMARRAY to understand the above code. So, I suspect many people, myself included, would take longer to understand the shorter code. It is all trade-offs, and knowing several ways of doing something is great.
Good find, I will have to add that to my bag of MATLAB tricks.
-Thanks,
Doug
Hey Doug
Thanks so much for the video..made me finally understand how to bin in matlab. One question thought how would you bin x-y-z data?
Thanks again
Darlene
@Darlene
http://blogs.mathworks.com/videos/2007/12/13/visualizing-the-density-of-a-data-cloud/
Enjoy,
Doug
I just loved this explanation! Thanks a lot, Doug!
Exactly the solution I was looking for!
Many thanks,
Geoff
Hi Doug, thanks for the explanation. I have a question related to your post. After getting the corresponding frequency of occurrence of y in each of the bins on the x-axis, I wanted to plot the data as a histogram plot. I want to come up with a histogram plot that looks like the ones on the following figure. I am not sure how to do it though. Any suggestion will be very helpful.
http://imageshack.us/photo/my-images/30/sampleplot.gif/
@irene,
How about a bar plot with bar.m?