Calculation with Certain Portion of the Matrices

조회 수: 2 (최근 30일)
Cem Tuncer
Cem Tuncer 2019년 4월 14일
댓글: Cem Tuncer 2019년 4월 14일
xm = 0:0.1:6; ym =3:0.1:9;
[x, y] = meshgrid(xm,ym);
angle = asind((-x.^2.*y.^2-y.^4+1296)./(2.*x.*y.^3));
angle = real(angle);
z2 = 6./(x.*sind(angle)+y);
figure
contourf(x,angle,z2,0.82:0.03:2.2,'ShowText','on');
For the above code, I want to calculate z2 for the matrix elements of angles having the values between (-40) to 20 degrees, other values must vanish from the matrix. I know for these purpose x and y matrices should match with the angle matrix and they also need to be arranged, but ı couldn't manage the issue.
As a note, limiting the plotting axis is not the point because I will use the data for another calculation, I want to clear out unwanted parts of the data.
  댓글 수: 1
Cem Tuncer
Cem Tuncer 2019년 4월 14일
Guys it seems working:
indices = find(angle<-50);
angle(indices) = NaN;
indices = find(angle>30);
angle(indices) = NaN;
But it gives some saw-like result, I am open to other suggestions.

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

채택된 답변

Guillaume
Guillaume 2019년 4월 14일
The only way you're going to avoid that sawtooth effect is by starting with a meshgridded x and angle and calculating y from that. That would involve working out the equation of y against angle and x. If you can't do that, then you can reduce but not completely elimiate the sawtooth effect by using a finer grid.
I find it a bit weird that it is the angle matrix that you set to NaN. For contourf it doesn't matter but I would have thought that setting the z2 matrix to NaN would make more sense if that's the one you're going to use for further calculation.
Note that find is rarely needed and it's certainly not needed in the code you wrote:
indices = angle < -50;
angle(indices) = NaN;
indices = angle > 30;
angle(indices) = Nan;
would produce the same result. This can be simplified into a one-liner:
angle(angle < -50 | angle > 30) = NaN;
and as said, it's probably better to alter z2 instead of angle, so I'd replace that by:
z2(angle < -50 | angle > 30) = NaN;
  댓글 수: 1
Cem Tuncer
Cem Tuncer 2019년 4월 14일
Thank you, it is better and accurate representation indeed. And I changed step size to obtain finer grid in meshgrid x-y, and it worked to eleminate sawtooth structure.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Line Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by