This is what I have so far...
%This M script generates a Gaussian ellipse with fading red contours
%Generate the colour map
redmap=zeros(64,3);
%Want red to remain constant
redmap(:,1)=1;
%Ensures that green and blue fade away equally.
for i=1:64
redmap(i+64)=1-(i/64);
redmap(i+128)=1-(i/64);
end
%Generate x and y coordinates
[x y]=meshgrid(-5:0.01:5, -5:0.01:5);
%Create Gaussian data, scew the x data to provide elliptical distrobution.
z=exp(-((x.^2)./7)-((y.^2)./2));
%Make a filled contour. Many contour lines so that the colour change is
%almost continuous. Use the set command to remove the patch outlines and
%then apply the colour map we generated at the start of the script.
[C h CF]=contourf(x,y,z,150);...
set(h,'LineStyle','None'); colormap(redmap);
Is there anyway to optimise this further?
Thanks in advance.
--
----------------------------------------
David R Gilson, MPhys AMInstP
Email: da...@davidgilson.co.uk / D.R.G...@maths.hull.ac.uk
Web: http://davidgilson.co.uk
<Hu | MP>, Hull Mathematical Physics Group, University of Hull
"...to boldly think what no one has thought before!"
Hi David,
You can define your redmap in a single line; no need for the loop:
redmap = [ones(64,1), 1-[1:64]'/64, 1-[1:64]'/64]; % OR redmap =
[ones(64,1) repmat(1-[1:64]'/64,1,2)];
The rest looks fine. The only thing I would add is that your contourf
command will take a moment to run. You create a pretty fine mesh of x, y
(and thus z) (1001 x 1001), and then generate only150 contours. If a coarser
mesh of values would suffice, you will get the same figure, faster, by
changing your stepsize in meshgrid to, say, 0.1.
Cheers,
Brett
Thanks :)
David.