MATLAB: How to plota a trace/line through the contour plot at specific points

computer visiondigital image processingdigital signal processingmachine learningstatistics

My code is:-
hold off
mu=[0 0];
sigma=[5 -2 ;-2 2];
x = -10:0.1:10; y = x;
[X,Y] = meshgrid(x,y);
F = mvnpdf([X(:) Y(:)], mu,sigma);
F = reshape(F,length(x),length(x));
contour(x,y,F);
xlabel('X'); ylabel('Y');
grid on
axis square
above is the code for marginal distribution , how can i plot a line through the above contour plot at y=-4:2:4??
To be more precise plotting a line through the 2-D contour plot is just like a conditionalizing over a fixed value…!!

Best Answer

mu=[0 0];
sigma=[5 -2 ;-2 2];
x = -10:0.1:10; y = x;
[X,Y] = meshgrid(x,y);
F = mvnpdf([X(:) Y(:)], mu,sigma);
F = reshape(F,length(x),length(x));
contour(x,y,F);
xlabel('X'); ylabel('Y');
grid on
axis square
%%DRawing line
yi=-4:2:4 ;
xi = interp1(y,x,yi) ;
hold on
plot(xi,yi,'r')