Finding weight of each grid in Matlab? - matlab

So I have two vectors*(x & y)* with x and y co-ordinate data points. I would like to put these points on grid kinda like a scatter plot and count the number of points within each grid like the weight of each grid using Matlab.
What would you guys suggest is the best way to do this? Any suggestion is appreciated

I assume you mean that you want to perform a 2D histogram of your x-y data.
You can use several tools from the file exchange:
http://www.mathworks.com/matlabcentral/fileexchange/9896-2d-histogram-calculation
http://www.mathworks.com/matlabcentral/fileexchange/1487
http://www.mathworks.com/matlabcentral/fileexchange/14205-2d-histogram

Related

Offset lineplot from Y-axis

I am working with a data stream and for different time points in this stream I have density estimates over a fixed set of X values.
Each of these sets of estimates would look something like this
I'd like to plot multiple curves like this sideways, similar to how it's done in this answer
I've looked through the documentation regarding plotting but didn't find a straight-forward solution for it.
While it's easy to turn such a plot sideways by simply switching the axes, I didn't find a possibility to offset this from the Y-axis
Does anyone have an idea how to tackle this?
Instead of plotting
plot(x,y)
plot
plot(k+y,x)
where k is the location of the plot along the x axis (2 or 4 in your example).

Contour Plot of own coordinates with attached scalar

I have the following coordinate system of (x,y) and attached z value to each coordinate. I need to keep the coordinates the same without using some linear fit function to change it into a grid system of some sort. Is there a way i can create a contour of that data using that data only and not using griddata or something.
x=[0.2,0.2,0.05,1.1,0.8,0.9,1.8,1.9,2.05];
y=[0,1.1,2.1,0.1,1.1,2.2,0.15,1.1,2.05];
z=[0,1,0,0,2,1,0,1,0;];
plot(x,y, 'bo')
The reason is i have another model with 540 thousand coordinate points that is a weird shape and if i start using the other functions it loses its shape and goes rectangular.
One option you have is to use fitto create a fit surface of your data, and then directly plot it. This also has the advantage to give you extra parameters to control the interpolation between your points.
f=fit([x',y'],z','linearinterp')
plot(f,'Style','Contour')
Will create something like:
And
f=fit([x',y'],z','cubicinterp')
plot(f,'Style','Contour')
Will smooth the interpolation into:
Please look here for more information on fit and fit plotting options
https://www.mathworks.com/help/curvefit/fit.html#inputarg_fitType
https://www.mathworks.com/help/curvefit/plot.html

Visualize 3D data in MATLAB

I have data on the form (x, y, z, v), in other words three spatial coordinates and one velocity magnitude. I would like to plot this in 3D, where the velocity magnitude is shown using color.
What is the best way to do this in MATLAB?
I assume you have trajectory data, so that your spatial coordinates represent the trajectory through space of one or more particles. In that case:
Have a look at quiver3 or coneplot.
If you want colored arrows, then have a look at quiver3d or quiverc (2D only) on the File Exchange.
If you only have 3 spatial coordinates and speed (= velocity magnitude), then your best bet is scatter3.
I could go on, but could you give me a bit more detail on what you want exactly?
Have you tried surf(x,y,z,v)?

Scatter non-square matrix

I would like to scatter matrix of any dimensions (height, width, depth). The problem is that scatter takes matrices of equal dimensions.
Is there any alternative way to achieve this?
I was thinking about complementing my matrix to square one and then minimizing the size and color of those points that are "virtual", but I'm trying to find a better solution.
Can anyone help?
Here is the way I intend this to work:
[x,y,z] = meshgrid(1:height, 1:widht, 1:depth);
scatter3(x(:), y(:), z(:), size, data_matrix(:));
To show purpose of this code: Say, I have temperature in a room stored in a matrix. I want to plot the temperature in a 3D plot. If there is a better way to achieve this then scatter (which seems to work for equal dimensions case), will be grateful to know it :D

3D scatterplot colored by Z-Value

I've been googling for a while but couldn't find a solution for my problem. I am an amateur matlab user and I would like to create a 3D scatterplot, for this I have a matrix containing several points in 3D space:
>> size(A)
ans =
2511 3
I was able to create a 3D scatterplot using "scatter3" function, but now I am stuck a bit at color-coding the 3D points.
scatter3(A(:,1),A(:,2),A(:,3));
This will plot the data, but now I would like to add a color coding based on the z-Value...
The colors themself don't matter too much. It could be a rainbow spectrum or a temperature spectrum or whatever. I just would like to colorcode them to distinguish the z-Values of the points.
Can anybody help me with this? Thank you!
You have to give some more arguments to scatter3.
scatter3(X,Y,Z,S,C);
S lets you specify areas for each markers (with a vector) or a single area for all the markers, while C lets you specify color. If C is a vector, its values will be linearly mapped to the current colormap. To change the colormap, call colormap(jet) for example. See the documentation on colormap.
Sorry if that's confusing. Short version:
scatter3(A(:,1),A(:,2),A(:,3),9,A(:,3));
colormap(jet); %# or other colormap