I use contourf function for plotting a 2D filled contour.
I get warning that some of the data points for Z are repeated and average values will be used in that case.
Can I somehow force Matlab to use the median values instead?
Thank you.
File: MyData.csv
Related
This might be simple and I apologize if it is so.
In matlab I have a double precision matrix which can theoretically have the range of +/- infinity.
I would to use the histogram function in matlab to change the values of the matrix.
For instance, if data elements fall within histogram bin 1 then I would like to assign the value of 1 to this and all of its instances.
Is there a quick and cheap way of doing this?
I have tried lookuptables etc but matlabs LUT is a pain.
Thank you for looking at my question
I think I just cracked it ...
Make a new function out of hist and after edges in the m file add this line:
[~,my_labels] = histc(y,edges,1);
and my_labels will contain your matrix with the histogram values instead of the actual values.
I have modeled my 1D data (1000*1 matrix) into 3 Gaussians, using
gmdistribution.fit(X,3)
How can I plot something Like this?
It shows the probability of a given point belonging to each class.
Write a function plotGaussian, which takes the mean, the variance, and a range of values. The function should generate the points to plot, and call the plot function. Then do hold on, and call plotGaussian 3 times.
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)
What is the default for the contours in a contourf function in matlab?
For example:
Z = peaks(20);
contourf(Z);
What do each of these contours represent? If I don't specify the second term in contourf e.g. contourf(Z,10) which would give 10 contour lines, how does matlab choose the number of contours?
You can look up the detailed algorithm for calculating the initial contour level step sizes from MATLABROOT\toolbox\matlab\specgraph\#specgraph\#contourgroup\refresh.m, around line 25.
Basically, Matlab divides the range into ~10 steps, but adjusts that number a bit depending on the exact value of the range of z-values.
There is no default. You are defining the number of contours by using:
Z=peaks(20);
This in effect returns an 20x20 [m,n] matrix of peaks which is stored in Z.
The ranges of the x-axis and y-axis are based on the size of array Z.
The number of contour lines and the values of the contour lines are taken from the minimum and maximum values of peaks inside the Z array.
The Z array is populated with the peaks() function which uses Normal Distribution (or Gaussian distribution).
As the documentation of the
contourf function says:
The number of contour lines and the values of the contour lines are chosen automatically based on the minimum and maximum values of Z. The ranges of the x-axis and y-axis are [1:n] and [1:m], where [m,n] = size(Z).
i am plotting a convolution in matlab for that purpose i create 2 arrays representing the values of the functions in various points.
x=[1:1000];
c=[1:1000];
t = linspace(-18,18,1000);
for k=1:1000, x(k)=input(t(k));
c(k)=h(t(k));
end;
plot(conv(c,x));
the thing is that it plots the conv against the place of the answer in the array.
i want to plot the conv against the 'n' that will give the value.
plotting against t,c or x from the example above does not give the righ answer. also the plot here is of length 1999.
creating a linspace of length 1999 will plot but it wont give the right answer.
any suggestions?