bootstrap.rand is a matrix with 253x10000 integer values ranging from 1 to 253.
The built-in hist() command returns:
hist(bootstrap.rand)
When building a histogram by using the barplot command I get a complete different result:
bar(histc(bootstrap.rand(:),unique(bootstrap.rand)))
Because of the y-axis in the first picture obviously it does not do what i want. Why this difference?
The functions hist and histc are not recommended by MATLAB:
hist is not recommended. Use histogram instead.
For more information, including suggestions on updating code, see Replace Discouraged Instances of hist and histc.
Instead use histogram which gives the wanted output:
bootstrap = randi(253,253,10000);
histogram(bootstrap)
The shape of bootstrap doesn't matter, it will always be treated as bootstrap(:).
Related
Output of plot(mat2gray(pdist(data, 'correlation')));
I see there about 3-5 trends, which I would like to visualize better.
I think the plot may not be the optimum here.
Its imshow(squareform(pdist(data, 'correlation'))) (equivalent to imshow(squareform(pdist(data, 'correlation'), 'tomatrix'))) is the following based on Dan's answer.
Image with normalized pdist values i.e. imshow(squareform( mat2gray(pdist(data, 'correlation')), 'tomatrix') ); colormap('parula');
However, I have some difficulties in interpreting the picture.
There seems to be like three eigenvalues if you consider a dark place like an eigenvalue.
What should I put here to the axes?
How can you visualize the output of dist correlation better?
How about
imshow(squareform(pdist(data, 'correlation')))
You might have to massage the result before calling imshow to make it either range form 0 to 1 or to be of type uint8 and range from 0 to 255
I have drawn a histogram of a variable I using the function hist available in Matlab R2012b.
hist(I(:),100);
I have got the following result, it is a histogram :
The problem is as follow: I don't care about the values on Zero following X-axis. I would like to draw a histogram without putting focus on the huge value of zeros.
I found this solution :
[counts,centers] = hist(I(:));
[~,i] = max(counts);
counts(i)= 0;
bar(centers,counts);
But it seems not good one !
Is there a way to specify bins interval without zero !? is there a way, using code, to zoom in so that I can recognize clearly the other bars ?
The documentation of the function hist is available here.
Any suggestion is a welcome.
If you don't care about zeros, don't pass them to hist:
hist(I(I~=0),100)
Is there a way to get the result object of a call to histogram() without the histogram plot?
I want to use the results in a script without figures being generated.
Thanks.
On octave you can use
values = hist(...);
without generating a plot. hist will also return the bin centers if you provide a second output argument. Note that Mathworks recommends using histogram and histcounts (see below) instead. You may also be interested in histc which takes the position of the bin edges as an input.
On current Matlab versions you can also use histcounts to get the bin counts and edges.
Please see also the documentation of hist and histcounts.
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)
This should be a really simple question, but for some reason I'm getting unreasonably confused and the Matlab documentation isn't helping.
Given a uniform grid of coordinates (x_i,y_j,z_k), I want to make a 3-dimensional array F in Matlab such that F(i,j,k)=f(x_i,y_j,z_k). The following is obviously incorrect:
x=linspace(-1,1,100) % uniform mesh on [-1,1]^3
[X,Y,Z]=meshgrid(x);
f=X.*Y.*sin(pi*Y.*Z) % for example
Do I need to use permute somewhere? I know that I could simply make a triple loop, but as we know that is slow.
Thanks!
Use ndgrid instead of meshgrid to avoid the unwanted permutation between first and second dimensions.
From the documentation (see also here):
MESHGRID is like NDGRID except that the order of the first two input
and output arguments are switched (i.e., [X,Y,Z] = MESHGRID(x,y,z)
produces the same result as [Y,X,Z] = NDGRID(y,x,z))