contour plot for different values

2 views (last 30 days)
Beena
Beena on 31 Jul 2014
Answered: Mike Garrity on 1 Aug 2014
Hi I am using this code to plot contours of normal marginals
A=[1 2;3 4];
B=[3 8;5 9];
MA=mean(A,2);
MB=mean(B,2);
rho=corrcoef(A,B);
MU1 = MA;
SIGMA1 = rho;
MU2 = MB;
SIGMA2 = [1 0; 0 1];
u=linspace(-8,8,1000);
[X,Y]= meshgrid(u); % mashgrid of u
F1 = mvnpdf([X(:),Y(:)],MU1',SIGMA1);%pdf of marginals
F2 = mvnpdf([X(:),Y(:)],MU2',SIGMA2);%pdf of marginals
F1 = reshape(F1,length(Y),length(X));
F2 = reshape(F2,length(Y),length(X));
Fa=mvncdf([X(:),Y(:)],MU1',SIGMA1); %cdf of marginals
Fb=mvncdf([X(:),Y(:)],MU1',SIGMA1); %cdf of marginal
F = copulapdf('Gaussian',[Fa(:), Fb(:)],0);% Gaussian copula of marginals
F = reshape(F,length(Y),length(X));
mvd = reshape(F,1000,1000).*F1.*F2; % computing multivariate density of copula and marginals
figure;
contour(X,Y,mvd);
I want to plot a contour plot of different values of F1 and F2 but when I am using contour (X,Y,mvd,[val1,val2]); it just gives one line of the contour plot. But I want the complete contour plot of using just two values of coordinates.Please help with this Thanks in advance for your help.
kind regards Ben

Answers (1)

Mike Garrity
Mike Garrity on 1 Aug 2014
What you're doing looks fine, but I don't know what val1 and val2 were. If I do this:
contour(X,Y,mvd,[.04e-3, .12e-3])
I get two levels.
If you do this:
[~,h] = contour(X,Y,mvd)
then h will be a handle to a contour object. You can then ask it what its doing and try different levels.
For example,
get(h,'LevelList')
ans =
1.0e-03 *
0.02 0.04 0.06 0.08 0.10 0.12 0.14 0.16 0.18
Do those values look like the ones you were passing in?
You can then change the levels like this:
set(h,'LevelList',[.03 .09]*1e-3)

Categories

Find more on Contour Plots in Help Center and File Exchange

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!