Borrar filtros
Borrar filtros

How to extract the X and Y values from a contourf graph

10 visualizaciones (últimos 30 días)
I am trying to generate a list of X and Y coordinates following the outline of a contourf graph. However, when I attempted the solutions that I found in other questions it resulted in an empty variable. Attached is my code to generate the contour graph and the resulting figure, thank you in advance for your help.
FinalMatrix = [AA AB AC AD AE AF AG AH AI AJ AK AL];
asdf = max(FinalMatrix,[],'all');
asdf = asdf*.25;
FinalMatrix(FinalMatrix<asdf) = NaN;
x = 1:12;
y = 1:7;
[X,Y] = meshgrid(x,y);
contourf(X,Y,FinalMatrix,[1 1])
[F,L] = contourf(X,Y,FinalMatrix,[1 1]);
  2 comentarios
the cyclist
the cyclist el 15 de Jun. de 2023
Editada: the cyclist el 15 de Jun. de 2023
It is unclear to me what you have as input. Do you have only the image (e.g. a *.jpg file?), or do you have the MATLAB *.fig file? (I assume that you do not have the original data used to create the figure, or it would be trivial.)
Can you upload what you have? You can use the paper clip icon in the INSERT section of the toolbar.
Aidan Fishenden
Aidan Fishenden el 15 de Jun. de 2023
I do have the data used to create the figure, I've attached it here. Sorry, this is my first project with matlab.

Iniciar sesión para comentar.

Respuesta aceptada

the cyclist
the cyclist el 15 de Jun. de 2023
The problem is that you set the levels input to contourf to [1 1], but it is impossible to have contours there, because all your data are greater than 1. So, it makes sense that there are no contours.
If you don't set that (or set it to values where contour heights are possible), you will see the contour output.
load("matrix.mat","FinalMatrix")
x = 1:12;
y = 1:7;
[X,Y] = meshgrid(x,y);
figure
[F,L] = contourf(X,Y,FinalMatrix);
F
F = 2×129
40.0000 2.0161 2.0127 2.0000 1.7500 50.0000 5.7097 6.0000 50.0000 2.1774 2.1392 2.0000 1.4118 50.0000 5.0000 4.9012 60.0000 5.3871 6.0000 60.0000 2.3387 2.2658 2.0000 2.0000 60.0000 6.0000 5.8182 5.8947 60.0000 5.0000 4.0000 2.0161 2.0000 1.9524 1.7500 2.0000 1.0000 1.2500 4.0000 2.1774 2.0000 1.4762 1.0000 2.0000 4.8462 5.0000 2.0000 1.0000 1.5278 4.0000 2.3387 2.0000 1.0000 1.0000 3.0000 2.8095 3.0000 3.1053 2.0000 4.6538
  5 comentarios
the cyclist
the cyclist el 15 de Jun. de 2023
OK. One thing that still makes this difficult is that we don't know enough about how general this needs to be. For example, is the spike always at the upper edge of the matrix, or might it have edges all around? We don't know what assumptions are valid.
There is probably not a simple MATLAB function to do what you want. Maybe something in the Image Processing Toolbox would make this easy, but I am not personally knowledgeable about it.
What I suggest is, before you think about coding this, is to think about the algorithm (the "instructions") that the code needs to follow. Think about each of the steps. For example, the first step might be to identify the spike itself, rather than any other values. How would you tell another person how to do that? That will help you figure out the rule, which can then be coded.
We could write code based on assumptions and guesses, but it will probably be wrong.
Aidan Fishenden
Aidan Fishenden el 15 de Jun. de 2023
Understood, thank you.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre 2-D and 3-D Plots en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by