Constraints on meshgrid. Remove points outside function
27 views (last 30 days)
Show older comments
Martin Mikkelsen
on 16 May 2020
Commented: Martin Mikkelsen
on 17 May 2020
I need help constraining the entries in my meshgrid. So far the entries take values on the entire x-axis and y-axis.
I have a figure consisting of an upper curve and a lower curve. Any point outside the curves should be equal to nan and not be coloured.
M = 3749.41; %MeV
m1 = 3728.4; %MeV
m2 = 0.5109989461; %MeV
m3 = 0.5109989461; %MeV
lambda = @(x,y,z) (x-y-z).^2-4*y*z; %Triangle function
s = M^2; %Mass of the decaying particle squared
s1 = linspace((m1+m2).^2,(sqrt(s)-m3)^2,1000); %s1 = s12
s2 = linspace((m2+m3).^2,(sqrt(s)-m1)^2,1000); %s2 = s23
s3 = linspace((m1+m3).^2,(sqrt(s)-m2)^2,1000); %s3 = s31
s11 = @(s2) m1^2+m2^2-1./(2*s2).*((s2-s+m1^2).*(s2+m2^2-m3^2)-lambda(s2,s,m1^2).^(1/2).*lambda(s2,m2^2,m3^2).^(1/2)); %upper half of boundary curve
s12 = @(s2) m1^2+m2^2-1./(2*s2).*((s2-s+m1^2).*(s2+m2^2-m3^2)+lambda(s2,s,m1^2).^(1/2).*lambda(s2,m2^2,m3^2).^(1/2)); %lower half of boundary curve
hold on
plot(s2,s11(s2),'r','LineWidth',2)
plot(s2,s12(s2),'r','LineWidth',2)
mr = 0.0167*1000; %Pole mass in MeV
gamma01 = 0.002*1000; %Decay width in MeV
A1 =@(a) sqrt(a)./(mr^2-a-1i*gamma01*sqrt(a)); %Breit-Wigner
T0 = 1;
Matrixelement = @(b) T0.*A1(b);
costheta = @(s1) 2.*(sqrt(s1)-min(sqrt(s1)))./(max(sqrt(s1))-min(sqrt(s1)))-1;
lpol = @(s1) legendreP(1,costheta(s1));
A1 =@(a) sqrt(a)./(mr^2-a-1i*gamma01*sqrt(a));
[x,y] = meshgrid(s2,[s11(s2),s12(s2)]);
hold on
mscale1 = @(x) (Matrixelement(s2) - min(Matrixelement(s2)))./( max(Matrixelement(s2)) - min(Matrixelement(s2))); %normalize
mscale2 = @(a) (Matrixelement(s2) - min(Matrixelement(s2)))./( max(Matrixelement(s2)) - min(Matrixelement(s2))); %normalize
z = (mscale1(x).*conj(mscale1(x))).*costheta(y).^2; %abs(1/2.*(3.*costheta(y).^2-1)); %remember spin
contourf(x,real(y),real(z),'edgecolor','none')
plot(s2,s11(s2),'r','LineWidth',2)
plot(s2,s12(s2),'r','LineWidth',2)
colorbar
All I need is to make the meshgrid only to take values inside the curve.
0 Comments
Accepted Answer
Matt J
on 16 May 2020
Just apply logical indexing on the appropriate region and set it to NaN,
bad=(y<s11(s2)) | (y>s12(s2));
z(bad)=nan;
5 Comments
More Answers (0)
See Also
Categories
Find more on Earth, Ocean, and Atmospheric Sciences in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!