In matlab, if I have this code :
v=10;
for t=1:v
Rateall(1:v) = (1/2)*(log2(1+SINR1)+log2(1+SINR2));
distanceall(1:v)=pdist([randomclusters{1};randomclusters{2}],'euclidean');
end
Rateall has 10 values and distanceall has 10 values after the for loop. How to plot the cdf graph between both Rateall and distanceall?
Related
How to plot scree plot in matlab using Singular Value Decomposition(SVD)?
I have already calculate first and second factor and loadings.
[U,S,V] = svd(x);
ls1 = S(1,1)*V(:,1)';
ls2 = S(2,2)*V(:,2)';
I am beginner in Matlab, this is my code so far to plot function
A=[5:5:60];
alpha=[0:1:90].*(pi/180);
omega=[24];
for k = 1:12
A1=A(k);
B=[0:A1./5: A1];
for j = 1:6
for i = 1:91
I(k,j,i)=A(k)+B(j)*sin(2*alpha(i)+omega)*sin(2*alpha(i)+omega);
end
end
end
figure(1), plot(alpha, squeeze(squeeze(I(6,3,:))))
How do I plot relation between A and b
from each I at a set A and B.
and to use max and min functions
to get Imax and Imin.
And then I want to calculate PI, then plot PI vs (A,B) on a 3d plot.
can any one help?
Im trying to plot the following on MATLAB not sure how to do it?
Y-axis ranges from -200 to 200
X-axis ranges from 0 to 10
Now the function is
x = linspace (0,10,100);
Yin = 10*sin (2*pi*x);
Ym = Yin*4*cos(2*pi*x);
I'm trying to plot graph for (Yin, Ym) that will show me the range of 0 to 10 on X-axis and -200 to 200 and Y-axis
For the plotting part the answer is:
plot(x,Yin,x,Ym);
axis([min(x),max(x),-200,200]);
But be careful with Ym = Yin*4*cos(2*pi*x); since Yin and x (thus cos(2*pi*x)) are vectors, * is the matrix multiplication. Since both Yin and x have the same shape, it may raise an error. Depending on what you want, you may need the elment-wise multiplication operator .* instead: Ym = 4*Yin.*cos(2*pi*x);
I want to write a bimodal Probability Density Function (PDF with multiple peaks, Galtung S) without using the pdf function from statistics toolbox. Here is my code:
x = 0:0.01:5;
d = [0.5;2.5];
a = [12;14]; % scale parameter
y = 2*a(1).*(x-d(1)).*exp(-a(1).*(x-d(1)).^2) + ...
2*a(2).*(x-d(2)).*exp(-a(2).*(x-d(2)).^2);
plot(x,y)
Here's the curve.
plot(x,y)
I would like to change the mathematical formula to to get rid of the dips in the curve that appear at approx. 0<x<.5 and 2<x<2.5.
Is there a way to implement x>d(1) and x>d(2) in line 4 of the code to avoid y < 0? I would not want to solve this with a loop because I need to convert the formula to CDF later on.
If you want to plot only for x>max(d1,d2), you can use logical indexing:
plot(x(x>max(d)),y(x>max(d)))
If you to plot for all x but plot max(y,0), you just can write so:
plot(x,max(y,0))
The function called DicePlot simulates rolling 10 dice 5000 times.
The function calculates the sum of values of the 10 dice of each roll, which will be a 1 ⇥ 5000 vector, and plot relative frequency histogram with edges of bins being selected in where each bin in the histogram represents a possible value of for the sum of the dice.
The mean and standard deviation of the 1 ⇥ 5000 sums of dice values will be computed, and the probability density function of normal distribution (with the mean and standard deviation computed) on top of the relative frequency histogram will be plotted.
Below is my code so far - What am I doing wrong? The graph shows up but not the extra red line on top? I looked at answers like this, and I don't think I'll be plotting anything like the Gaussian function.
% function[]= DicePlot()
for roll=1:5000
diceValues = randi(6,[1, 10]);
SumDice(roll) = sum(diceValues);
end
distr=zeros(1,6*10);
for i = 10:60
distr(i)=histc(SumDice,i);
end
bar(distr,1)
Y = normpdf(X)
xlabel('sum of dice values')
ylabel('relative frequency')
title(['NumDice = ',num2str(NumDice),' , NumRolls = ',num2str(NumRolls)]);
end
It is supposed to look like
But it looks like
The red line is not there because you aren't plotting it. Look at the documentation for normpdf. It computes the pdf, it doesn't plot it. So you problem is how do you add this line to the plot. The answer to that problem is to google "matlab hold on".
Here's some code to get you going in the right direction:
% Normalize your distribution
normalizedDist = distr/sum(distr);
bar(normalizedDist ,1);
hold on
% Setup your density function using the mean and std of your sample data
mu = mean(SumDice);
stdv = std(SumDice);
yy = normpdf(xx,mu,stdv);
xx = linspace(0,60);
% Plot pdf
h = plot(xx,yy,'r'); set(h,'linewidth',1.5);