how can we find the coordinates of more points besides the points automatically generated by Contour in MATLAB?

I have already known the usage of Contour in MATLAB. NevertheIess, I have an additional question, how can we find the coordinates of more points besides the points automatically generated by Contour? Is interpolation or B-spline fitting available? Looking forward to your reply.

2 Comments

Is there a relation between Z and X,Y values? or is Z independent?
It would help if you can provide more information as to what you are working with.
Thank you for your message in advance. I'm working with the binary function reconstruction, so the relation between Z and X,Y values is clear due to the B-spline basis function polynomial. Now, I want to generate isolines with different values and obtain some corresponding points, I try to use 'Contour(X,Y,Z)', but the corresponding points are not enough at my request. I want to know how to get more points on the isolines which are generated by the 'Contour'.

Sign in to comment.

Answers (3)

You can define specific isolines —
[X,Y,Z] = peaks(50);
figure
contourf(X, Y, Z, 'ShowText',1)
title('Default Behaviour')
figure
contourf(X, Y, Z, [-2 -0.5 0 pi 2*pi], 'ShowText',1)
title('Selected Levels')
See the documentation section on levels for details.
.

3 Comments

Thank you for your answer. Maybe I doesn't express my problem clearly. I want to get uniform discrete sampling points on each isolines after generating some isolines by using 'Contour'. Is there any good way I can try?
I am not certain what you want to do, or how to interpret ‘uniform discrete sampling points’. If you request it, the first output from contour (or contourf) is a matrix of the contours, explained in the documentation as contour matrix M. You can then get the coordinates from it for each contour level. (This is straightforward but a bit complicated to code.) The matrix exists in two rows, the first row are the x-coordinates of the contour, and the second row are the y-coordinates. This is complicated a bit because the level each contour applies to is the column defined by the level information in the first row and the number of elements in that section of the matrix in the second row:
M = [Level(k) x(1) x(2) ...
Length(k) y(1) y(2) ...
That applies to each level. As I demonstrated, you can define the levels specifically.
You can interpolate the contour matrices for each level to have the same lengths using the interp1 function once you have isolated them in separate cell arrays (since they will have different lengths as contour function outputs).

Sign in to comment.

Not sure if you need more contour (more levels) or denser contour.
For the first case check the doc of contourf the level parameter
For denser points, interpolate te data before call contour
A=peaks(10)
A = 10×10
0.0001 0.0013 0.0053 -0.0299 -0.1809 -0.2465 -0.1100 -0.0168 -0.0008 -0.0000 0.0005 0.0089 0.0259 -0.3673 -1.8670 -2.4736 -1.0866 -0.1602 -0.0067 0.0000 0.0004 0.0214 0.1739 -0.3147 -4.0919 -6.4101 -2.7589 -0.2779 0.0131 0.0020 -0.0088 -0.0871 0.0364 1.8559 1.4995 -2.2171 -0.2729 0.8368 0.2016 0.0130 -0.0308 -0.4313 -1.7334 -0.1148 3.0731 0.4444 2.6145 2.4410 0.4877 0.0301 -0.0336 -0.4990 -2.3552 -2.1722 0.8856 -0.0531 2.6416 2.4064 0.4771 0.0294 -0.0137 -0.1967 -0.8083 0.2289 3.3983 3.1955 2.4338 1.2129 0.2108 0.0125 -0.0014 -0.0017 0.3189 2.7414 7.1622 7.1361 3.1242 0.6633 0.0674 0.0030 0.0002 0.0104 0.1733 1.0852 2.6741 2.6725 1.1119 0.1973 0.0152 0.0005 0.0000 0.0012 0.0183 0.1099 0.2684 0.2683 0.1107 0.0190 0.0014 0.0000
Ai=interp2(A,4,"spline"); % up sampling by 16 = 2^4
x = linspace(0,1,size(A,2));
y = linspace(0,1,size(A,1));
xi = linspace(0,1,size(Ai,2));
yi = linspace(0,1,size(Ai,1));
ax1 = subplot(2,1,1); contourf(x,y,A,0.5+[0 0]); axis equal
ax2 = subplot(2,1,2); contourf(xi,yi,Ai,0.5+[0 0]); axis equal
linkaxes([ax1,ax2])
xlim([0.4 0.7])
ylim([0.4 0.7])

2 Comments

Thank you for your answer. Maybe I doesn't express my problem clearly. I want to get uniform discrete sampling points on each isolines after generating these isolines by using 'Contour'. Is there any good way I can try?

Sign in to comment.

Categories

Products

Release

R2016a

Asked:

on 19 Sep 2023

Edited:

on 19 Sep 2023

Community Treasure Hunt

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

Start Hunting!