I have a number of float arrays, and my purpose is to create a histogram for them. I want to get a graph of the values' frequencies - one graph per each array. and I need all the graphs to be shown on the same window, like this Opencv example does for rgb color histogram. I'm looking for a way to do it using OpenCv or to dump the values out to a file and do the histogram using Matlab. Any idea?
Matlab has a built-in histogram function - hist. It can calculate the histogram, or plot it, or both. For example, if f is a list of files with data you can use
for i=1:length(f)
d=importdata(f(i));
subfigure(length(f),1,i);
hist(d);
end
(Of course, you have to tweak the data importing thingy to make it work. I don't know what the format of your data is in)
Related
I have an image I which pixel intensities fall within the range of 0-1. I can calculate the image histogram by normalizing it but I found the curves is not exactly the same as the histogram of raw data. This will cause some issue for the later peaks finding process(See attached two images).
My question is in Matlab, is there any way I can plot the image histogram without normalization the data so that I can keep the curve shape unchanged? This will benefit for those raw images when their pixel intensities are not within 0-1 ranges. Currently, I cannot calculate their histogram if I don't normalize the data.
The Matlab code for normalization and histogram calculation is attached. Any suggestion will be appreciated!
h = imhist(mat2gray(I));
Documentation of imhist tells us that the function checks the data type of the input and scale the values accordingly. Therefore, without testing with your attached data, this may work:
h = imhist(uint8(I));
An alternatively you may scale the integer-representation to floating-representation, by either using argument of mat2gray
h = imhist(mat2gray(I, [0,255]));
or just divide it.
h = imhist(I/255);
The imhist answer in this thread describing normalizing or casting is completely correctly. Alternatively, you could use the histogram function in MATLAB which will work with unnormalized floating point data:
A = 255*rand(500,500);
histogram(A);
Working in Matlab...
I have a long vector of data vec that I want to make a Q-Q plot of against a Student-t distribution for various values of t. I know qqplot(vec) produces a plot against a normal distribution. I know from here that I can use other distributions by inserting them as a second parameter qqplot(vec,dis).
I can make other distributions with makedist (see mathworks.com/help/stats/makedist.html) but Student-t isn't an option there that I can see. There are the functions tpdf, tcdf etc. about Student-t (see http://www.mathworks.com/help/stats/students-t-distribution-1.html) but how do I use them to make a distribution item to use in the Q-Q plot? Or is there another technique to get the plot I want?
I haven't used Matlab in about a decade, so I can't give specific syntax. That said, if vec has length n you should be able to create a vector of t-values corresponding to quantiles i / (n+1) for i=1,...,n using tinv. Then do a qqplot of vec vs. the t-vector.
I am wondering how, in Matlab, to plot a continuous pdf with the following information?
mean=-0.3731
standard deviation= 5.6190
skewness=-3.0003
kurtosis=13.1722
or alternative how do I plot a continous pdf that is not normal? (like it is skewness and has kurtosis, etc)
Thanks!
Those parameters don't define a distribution, but normally you would use "makedist" in matlab to generate a probability distribution object and then plot it.
The following thread has some discussion on defining a distribution. How to generate distributions given, mean, SD, skew and kurtosis in R?
Based on your comment below, I think you are looking for something like the following functio that generates a m by n matrix of random values with the following parameters:
r = pearsrnd(mu,sigma,skew,kurt,m,n)
I have about 10000 floating point data, and have read them into a single row matrix.
Now I would like to plot them and show their distribution, would there be some simple functions to do that?
plot() actually plots value with respect to data number...which is not what I want
bar() is similar to what I want, but actually I would like to lower the sample rate and merge neighbor bars which are close enough (e.g. one bar for 0.50-0.55, and one bar for 0.55-0.60, etc) instead of having one single bar for every single data sample.
would there be a function to calculate this distribution by dividing the range into small steps, and outputting the prob density in each step?
Thank you!
hist() would be best. It plots a histogram, with a lot of options which you can see by doc hist, or by checking the Matlab website. Options include a specified number of bins, or a range of bins. This will plot a histogram of 1000 normally random points, with 50 bins.
hist(randn(1000,1),50)
I have a 3D data set representing a grid of photosensors which unfortunately were not steady during use. I have estimated the pdf for the motion of the detector and I want to find the expectation value for each sensor. As I don't want to reflect my pdf (i.e. I want f(t) not f(t-tau)) I don't think I can use the matlab convolve function. Is there a function that will do what I want or should I just get on with it? I've found movavg but it seems to do something else or maybe I just haven't followed it correctly.
Also, as I'm faily new to matlab, from C, I tend to use for loops which I'm aware is not the way to use Matlab. Is there an easy way to convert my 1-D pdf to a 3D matrix that will only operate in one axis (z in this case). Something like repmat(i, j, pdf).
Thanks
The expected value of a pdf is the integral over the product of the grid values and the pdf values at the corresponding grid points.
To integrate over a 3D-Grid, use the Matlab function triplequad (doc). As an example, let us compute the expected x value:
expectedx = triplequad(pdfxfun,xmin,xmax,ymin,ymax,zmin,zmax)
pdfxfun in this call must be a function handle which for any (x,y,z) point it receives should return the product of the pdf value at that point and x. In your case, this could probably be achieved by interpolation over your grid data. I don't know a 3D-interpolation function in Matlab, so probably you have to work on this for yourself. Roughly, what you would do is:
function pdfvalue = pdfinterpolation(x,y,z,Xgrid,Ygrid,Zgrid,pdfdata)
% compute interpolated pdfvalue at (x,y,z) from griddata and pdfdata
Then, pdfxfun above can be defined as anonymous function in the call to triplequad:
pdfxfun = #(x,y,z) x*pdfinterpolation(x,y,z,myxgrid,myygrid,myzgrid,pdfdata)
expectedx = triplequad(pdfxfun,xmin,xmax,ymin,ymax,zmin,zmax)