I'm a little bit stuck on how to plot a histogram in MatLab, and typing help hist in MatLab does not make me any wiser. So I would appreciate any help!
Basically my problem is very simple. I have a vector, V, with five values, where each value represent the volume of a certain layer of the Earth. I simply want to create a histogram of these data, where the x-axis in my histogram should say "Inner Core", "Outer Core", etc., while the y-axis will display the volume. I've tried using the hist-command in various ways, but I can't get this to work. For instance, if I just type hist(V), the volume-values actually show up on the x-axis, and not the y-axis.
If anyone can help me how to make this simple histogram I will be very grateful! According to the instructions on my homework, I have to use the hist-command.
What you actually what is a bar plot.
bar([4,20,10,3,8])
Related
I am currently trying to use spectral-methods to analyse topographic landscapes.
When i FFT the landscape and plot the power-spectrum. From the power-spectrum an orientation of the structures in the landscape can be found.
2D power-spectrum:-
In this power-spectrum, i would like to make a cross-section.
This is easy when the peak amplitude orientation is along the x or y-axis.
But for this area (and others), this is not the case.
Cross-section from another area - orientated along the y-axis:-
My problem is i want to make a cross-section along the peaks in 1, and i just cant seem to figure it out how.
If anyone could point me towards some solution for this. Been stuck here for a couple of days now.
Edit 1
I would like the cross-section, to be a line along the peak orientation.
Edit 2
Improved the first image to show where i want my cross-section
My solution was, as GameOfThrows suggested:
Pick 2 (or more) points on the orientation i want
used Least squares on the points to create the line
Setup a meshgrid for the interpolation.
Use the interp2 function on the new line.
define a proper axis for the section
In my final cross section i ended up having multiple lines in it, that way i was sure to hit the max amplitudes.
i was a little with the answer to my question, but i have been busy :)
You can use ginput built-in matlab function to store 2 (x,y) coordinates of your power spectrum and then use this values to delimit a profile to be interpolated.
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 new to matlab and stackexchange too.
I wish to reproduce a colorbar for my own work (guess it was made using tecplot) preferably in MATLAB or python (matplotlib).
Here's an example of what I want to reproduce:
http://iopscience.iop.org/0963-0252/23/1/015007/downloadHRFigure/figure/psst484284fig14
My idea is to have a script which can be run on any x-y-z type of data such that this colorbar is applied in a way that all the colors are used (presume it will be some kind of rescaling?)
This colorbar does not need to display the actual values but just min and max will suffice.
Many thanks for all your help and suggestions.
This answer is for matlab. Since you do not say anything about recreating the colormap I assume that you know how to do that. However, if not, try the colormap editor.
surf(peaks(30));
colormapeditor;
Where peaks is a function creating some good demo data. The colormap can the be obtained from the figure. About your problem: Normally the colormap is automatically scaled to use the full spectrum of your colormap. If this for some reason does not work, set the CLim property to the range of your spectrum. That can for example be the maximum and minimum for your data or some other suitable range.
Good luck!
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.
I have a set of data that I plot but the points on the graphs are so closed to each other that you can't see them well nd neither their values because even when I zoom in I can't get to them all. Now what I want to do is to space them out without changing their actual values on the graph. Is the a function or any other ways to do that? I've tried changing the axis and the scale but it didn't help. Mostly those points are in the Y direction. Please help What I really mean is though these points are closed to each other I'd like to create and interval between them so they don't pile up on each other
You can make the vector you are trying to plot to be more sparse taking points after some defined intervals:
plot(x(1:10:end),y(1:10:end))
In this example, I plotted each tenth point. Does it help?