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

조회 수: 4 (최근 30일)
Aidan Fishenden
Aidan Fishenden 2023년 6월 15일
댓글: Aidan Fishenden 2023년 6월 15일
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
the cyclist
the cyclist 2023년 6월 15일
편집: the cyclist 2023년 6월 15일
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 2023년 6월 15일
I do have the data used to create the figure, I've attached it here. Sorry, this is my first project with matlab.

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

채택된 답변

the cyclist
the cyclist 2023년 6월 15일
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
the cyclist
the cyclist 2023년 6월 15일
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 2023년 6월 15일
Understood, thank you.

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

추가 답변 (0개)

카테고리

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

제품


릴리스

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by