Constraints on meshgrid. Remove points outside function

조회 수: 23 (최근 30일)
Martin Mikkelsen
Martin Mikkelsen 2020년 5월 16일
댓글: Martin Mikkelsen 2020년 5월 17일
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.

채택된 답변

Matt J
Matt J 2020년 5월 16일
Just apply logical indexing on the appropriate region and set it to NaN,
bad=(y<s11(s2)) | (y>s12(s2));
z(bad)=nan;
  댓글 수: 5
Matt J
Matt J 2020년 5월 17일
Check to make sure you’ve constructed the logical array “bad” correctly.
Martin Mikkelsen
Martin Mikkelsen 2020년 5월 17일
I changed it to
bad=(y>=s11(s2)) | (y<=s12(s2));
And that fixed the problem. Thank you so much! I really appreciate it.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Earth, Ocean, and Atmospheric Sciences에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by