필터 지우기
필터 지우기

Specify value on a contour with a value that is not in the matrix, it is possible ?

조회 수: 1 (최근 30일)
Hello !
I have an interrogation. I have a matrix with m rows and n columns and I plot this matrix with the contour function. In this matrix, there are some values positive and negative. To distinguish negative and positive part I would like to plot a line at 0 but in my matrix, I don't have exactly the value 0. There is a method or a function to help me ?
Thanks in advance

채택된 답변

Star Strider
Star Strider 2021년 7월 8일
Yes.
Use the levels argument.
M = (-1:0.11:1).'*(-1:0.9:1);
figure
contour(M, 'ShowText','on')
hold on
contour(M, [0 0], 'ShowText','on', 'LineStyle','--','Color','k') % Specific Contour At 0
hold off
This plot already plots the 0 contour, however the second contour call specifically plots the 0 contour with a black dashed line.
.

추가 답변 (1개)

Chunru
Chunru 2021년 7월 8일
편집: Chunru 2021년 7월 8일
Sure you can.
% a is integer
a=magic(6)
a = 6×6
35 1 6 26 19 24 3 32 7 21 23 25 31 9 2 22 27 20 8 28 33 17 10 15 30 5 34 12 14 16 4 36 29 13 18 11
% We specify the level as decimal number so it is not in the data a
contour(a, [2.1 5.9 20.4], 'ShowText', 'on')
% Now make +ve and -ve values.
b = a - 3.5
b = 6×6
31.5000 -2.5000 2.5000 22.5000 15.5000 20.5000 -0.5000 28.5000 3.5000 17.5000 19.5000 21.5000 27.5000 5.5000 -1.5000 18.5000 23.5000 16.5000 4.5000 24.5000 29.5000 13.5000 6.5000 11.5000 26.5000 1.5000 30.5000 8.5000 10.5000 12.5000 0.5000 32.5000 25.5000 9.5000 14.5000 7.5000
figure
contour(b, [-1 0 5], 'showtext', 'on')
  댓글 수: 1
Gaétan Andriano
Gaétan Andriano 2021년 7월 8일
Thank you for you help !
I've found another MATLAB Answers that can be interesting if other people got the same problem : https://fr.mathworks.com/matlabcentral/answers/413565-shaded-contour-and-line-contour-in-one-contourf

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

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by