Doug, I am a little confused…I assume x and y are just random coordinates…you then created xd, yd…what is this actually?? How did you do it? Then in linespace you use x,y again, but in interp you use xd,yd. I think I understand the concept, but I’m lost in the details. Can you post all the code so I can run what you did??
Thanks for the tutorial. Nice thing, I never came up against accumarray which seems to be very useful!
But actually there is a mistake when calculating the BIN-number: since interp1 assigns the nearest value in every dimension, all data points say in x-direction belonging to BIN 1 and half of them in BIN 2 will be assigned to (1,:). Correct should be interpolating to
xr = interp1(xi,0.5:numel(xi)-0.5,xd,'nearest')';
yr = interp1(yi,0.5:numel(yi)-0.5,yd,'nearest')';
In the example code, the data from xd will be plotted on the Y axis, and yd on the X axis. To get a properly labeled graph, with the X data along the X axis, you actually need to say:
surf(xi, yi, Z');
Why is that? In the example, we have
Z = accumarray([xr yr], 1, [n n]);
For instance, if something falls in the 1st X-bin and the 5th Y-bin, it will get counted in Z(1,5). But, the MATLAB plotting commands like SURF and CONTOUR take their inputs in the opposite way: To have something show up at (1,5) in the graph, it should be in Z(5,1).
Hope this is useful to the next person who’s thinking sideways!
Thanks for the video! I was able to use it effectively for 2 vectors (xd & yd).
I had some other questions about the extent to which I could use this code, or if there are other options available.
1. Is there an alternative to accumarray that will take negative inputs -or am I able to edit accumarray in a way that would allow it to take negative inputs?
2. Is there any way to have such a histogram plot for 3 vectors (xd, yd and zd)? What I would like to have is the x and y coordinates with z as the height and color coded by the frequency distribution. I am basically trying to visualize a special euclidean(2) space (since my z vector lies on polar coordinates). Is there any way to adapt your code to work for 3 vectors in this way?
I know these questions don’t directly apply to the working of the posted tutorial, but any suggestions would be very much appreciated!
Thanks in advance!
Hi there, I would like to ask if you know how to label the peak values of the data points in your 3D plot. I can’t seem to find any commands in MATLAB that are able to perform that function. Thank you.