Constraints on meshgrid. Remove points outside function

20 ビュー (過去 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 Center および File ExchangeEarth, 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