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

3 visualizaciones (últimos 30 días)
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

Respuesta aceptada

Star Strider
Star Strider el 8 de Jul. de 2021
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.
.

Más respuestas (1)

Chunru
Chunru el 8 de Jul. de 2021
Editada: Chunru el 8 de Jul. de 2021
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 comentario
Gaétan Andriano
Gaétan Andriano el 8 de Jul. de 2021
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

Iniciar sesión para comentar.

Categorías

Más información sobre Contour Plots en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by