How to extract the X and Y values from a contourf graph
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Aidan Fishenden
el 15 de Jun. de 2023
Comentada: Aidan Fishenden
el 15 de Jun. de 2023
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]);
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1411584/image.jpeg)
2 comentarios
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.
Respuesta aceptada
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
5 comentarios
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.
Más respuestas (0)
Ver también
Categorías
Más información sobre 2-D and 3-D Plots en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!