I am using matlab to process data to get a radius distribution function. Now I get data(an array) of different distances of other atoms to 1 specific atom.
I used the "hist" command (hist(radius1,400)) and get a histogram:
But what I want is a curve, like this:
http://upload.wikimedia.org/wikipedia/commons/3/31/Lennard-Jones_Radial_Distribution_Function.svg
I tried some fit command, but it would give me a normal-distribution-like curve, which is not what I want. actually no fit is fine, I only want a curve to show its varying.
The raw data was a 4000*1 array of radius, is there any other way to get a curve of the top of each bar of the histogram?
Thanks so much.
Instead of automatically plotting a histogram using hist, you can get it to output the values:
[x, c] = hist(radius1,400);
x is the data in each bin, c the centre of each bin, so this replicates a histogram and then overplots a line on it (which will just connect the top of each bar so it may not look as smooth as you hoped):
bar(c,x);
hold on
plot(c,x,'r');
It is possible to use fit with an anonymous function as a custom model, but that may be overkill in this situation.
Related
Is it possible to graphically represent linear transformations in MATLAB like the one shown below?
In particular, I'm looking for a way to represent the way a coordinate grid might become squished, stretched, or rotated after a matrix multiplication has been performed. I've tried using meshgrid(x,y) to plot the grid but I've been having trouble getting it to display properly. Ideally, it would be nice to see the way that the transformation acts on a unit square (and, if possible, to see the transformation being performed in a continuous fashion, where you can see the graphs morphing into each other). However, I'm willing to sacrifice these last two requirements.
Here is the code I have used so far:
x = -10:2:10;
y = -10:2:10;
[X,Y] = meshgrid(x,y);
plot(X,Y)
For some reason, only vertical lines have been plotted. (The documentation says it will display a square grid.)
please read the plot doc.
the problem is that what you are doing is trying to plot mash matrixes in a plot not by using mesh or something like that.
you may find this very helpful.
I have 8 plots which I want to implement in my Matlab code. These plots originate from several research papers, hence, I need to digitize them first in order to be able to use them.
An example of a plot is shown below:
This is basically a surface plot with three different variables. I know how to digitize a regular plot with just X and Y coordinates. However, how would one digitize a graph like this? I am quite unsure, hence, the question.
Also, If I would be able to obtain the data from this plot. How would you be able to utilize it in your code? Maybe with some interpolation and extrapolation between the given data points?
Any tips regarding this topic are welcome.
Thanks in advance
Here is what I would suggest:
Read the image in Matlab using imread.
Manually find the pixel position of the left bottom corner and the upper right corner
Using these pixels values and the real numerical value, it is simple to determine the x and y value of every pixel. I suggest you use meshgrid.
Knowing that the curves are in black, then remove every non-black pixel from the image, which leaves you only with the curves and the numbers.
Then use the function bwareaopen to remove the small objects (the numbers). Don't forget to invert the image to remove the black instead of the white.
Finally, by using point #3 and the result of point #6, you can manually extract the data of the graph. It won't be easy, but it will be feasible.
You will need the data for the three variables in order to create a plot in Matlab, which you can get either from the previous research or by estimating and interpolating values from the plot. Once you get the data though, there are two functions that you can use to make surface plots, surface and surf, surf is pretty much the same as surface but includes shading.
For interpolation and extrapolation it sounds like you might want to check out 2D interpolation, interp2. The interp2 function can also do extrapolation as well.
You should read the documentation for these functions and then post back with specific problems if you have any.
I am trying to program a matlab code in R2012a that will allow a color representation of temperature change on a surface based on different corresponding height and temperature measurements. Then end goal would be to combine multiple images together to get some sort of a jpeg. The temperatures I recorded were time specific which is why it would be beneficial in the end to have a visual depicting this temperature change over time.
It has been a little bit of time since I have used matlab, and I have never created something This complicated. It has me a little over whelmed and wondering where to start.
Thanks for any and all advice!
You might want to look at the avifile documentation for details on how to create a movie from a series of frames, there is a nice example that should make it clear enough.
Now to generate the frames needed for the avi file. Here, the meshgrid and surf functions come in handy. meshgrid generates two coordinate matrices with x and y coordinates for every point on your plate, surf then allows you to plot a surface with colors given by the temperatures at these positions. For example:
[x,y] = meshgrid(1:5,1:10) % generate a 10*5 plate with step size 1
z = rand(10,5) % height of the plate for a given position
c = rand(10,5) % color values, these should be your (time-dependent) temperatures
surf(x,y,z,c)
It is not clear to me whether you actually have a curved surface (requiring three coordinates to define each position), or just a simple plate. If it is just a simple plate, you can just set z = ones(size(x)) to obtain an uniform height.
I'm creating a line plot, where the y value of each point is the average value of vector i. The x value of each point is i.
I want to visualise the distribution of numbers in each vector, preferably all on the same graph.
Is there a way I can make a bar graph, where each bar, i, is something like a colorbar, representing the histogram of vector i. So essentially I want to end up with 20 or so bars, each being a histogram.
Or if there is a better way to visualise numerous histograms on a single plot, I'd like to hear it.
I solved the problem using Dan's solution. I took a histogram of each vector (with specific bin intervals), and stored them all in a 2D matrix (Each column is a complete histogram). Then displayed it with image() (Don't have access to imshow).
I did have to mess around with the axis labels though, as the image() function was plotting it according to the coordinates of the 2D matrix, rather than the values in the original vectors. Fixed that up with some calls to set(gca,'YTickLabel/YTick'). Also had to set the YDir back to 'normal' rather than 'reverse'. I think image() was flipping it.
I have a 3D data set of a surface that is not a function graph. The data is just a bunch of points in 3D, and the only thing I could think of was to try scatter3 in Matlab. Surf will not work since the surface is not a function graph.
Using scatter3 gave a not so ideal result since there is no perspective/shading of any sort.
Any thoughts? It does not have to be Matlab, but that is my go-to source for plotting.
To get an idea of the type of surface I have, consider the four images:
The first is a 3D contour plot, the second is a slice in a plane {z = 1.8} of the contour. My goal is to pick up all the red areas. I have a method to do this for each slice {z = k}. This is the 3rd plot, and I like what I see here a lot.
Iterating this over z give will give a surface, which is the 4th plot, which is a bit noisy (though I have ideas to reduce the noise...). If I plot just the black surface using scatter3 without the contour all I get is a black indistinguishable blob, but for every slice I get a smooth curve, and I have noticed that the curves vary pretty smoothly when I adjust z.
Some fine-tuning will give a much better 4th plot, but still, even if I get the 4th plot to have no noise at all, the result using scatter3 will be a black incomprehensible blob when plotted alone and not on top of the 3D contour. I would like to get a nice picture of the full surface that is not plotted on top of the 3D contour plot
In fact, just to compare and show how bad scatter3 is for surfaces, even if you had exact points on a sphere and used scatter3 the result would be a black blob, and wouldn't even look like a sphere
Can POV-Ray handle this? I've never used it...
If you have a triangulation of your points, you could consider using the trisurf function. I have used that before to generate closed surfaces that have no boundary (such as polyhedra and spheres). The downside is that you have to generate a triangulation of your points. This may not be ideal to your needs but it definitely an option.
EDIT: As #High Performance Mark suggests, you could try using delaunay to generate a triangulation in Matlab
just wanted to follow up on this question. A quick nice way to do this in Matlab is the following:
Consider the function d(x, y, z) defined as the minimum distance from (x, y, z) to your data set. Make sure d(x, y, z) is defined on some grid that contains the data set you're trying to plot.
Then use isosurface to plot a (some) countour(s) of d(x, y, z). For me plotting the contour 0.1 of d(x, y ,z) was enough: Matlab will plot a nice looking surface of all points within a distance 0.1 of the data set with good lighting and all.
In povray, a blob object could be used to display a very dense collection of points, if you make them centers of spheres.
http://www.povray.org/documentation/view/3.6.1/71/
If you want to be able to make slices of "space" and have them colored as per your data, then maybe the object pattern (based on a #declared blob object) might do the trick.
Povray also has a way to work with df3 files, which I've never worked with, but this user appears to have done something similar to your visualization.
http://paulbourke.net/miscellaneous/df3/