Understanding the working mechanism of contourc

could someone explain how contourc(x,y) works?
I am getting a 2xN array as a result but can not figure what are these numbers states for. If it is possible, could you write down the equivalent code for contourc without using any function similar to contourc.
Thanks a lot.

10 Comments

"could someone explain how contourc(x,y) works?"
As I recall, the algorithm used to be explained on some tech doc... but these are long gone.
But luckily for you I know that it was saved in the Internet Archive (scroll down to "The Contouring Algorithm"):
"I am getting a 2xN array as a result but can not figure what are these numbers states for"
The output matrix is explained here:
I agree that it is a very unhelpful output format.
You might like to use a wrapper function which returns a more useful and clearer output by downloading one of these:
"If it is possible, could you write down the equivalent code for contourc without using any function similar to contourc."
Could you share the mathmematical execution behind the contourc command? I am expecting a code for this made up with some of the matlab operators like for,if. Not any scripts or something else
which -all contourc
built-in (/MATLAB/toolbox/matlab/specgraph/contourc)
We don't distribute the source code for built-in functions.
If the source code were available, what would you want to do with it? How would you hope to use that information?
If you want to know how the contour matrix is calculated, open contours(). It's old, but it should still be hanging around in plainly readable m-code.
%CONTOURS Contouring over non-rectangular surface.
% CONTOURS computes the contour matrix C for use by CONTOUR,
% CONTOUR3, or CONTOURF to draw the actual contour plot.
%
% CONTOURS(...) is the same as CONTOURC except CONTOURS(X, Y, Z, ...)
% allows the specification of parametric surfaces (as for SURF).
% ...
Matt J
Matt J on 15 Nov 2023
Edited: Matt J on 15 Nov 2023
If you want to know how the contour matrix is calculated, open contours().
No, unfortunately it just sends the real work to built-ins.
DGM
DGM on 15 Nov 2023
Edited: DGM on 15 Nov 2023
Oh jeez. I skimmed through it and didn't catch that. I just saw some polyline handling, didn't see the call to contourc(), and thought "this looks meaty enough".
I suppose it's just as well, since we apparently aren't allowed to use any functions that would create the contour matrix.
the contourc function output is the x and y values respect to the specified contour levels, as explained in the accepted answer https://www.mathworks.com/matlabcentral/answers/13466-what-function-contourc-returns?s_tid=srchtitle . How are these x and y values selected? I am working on the small arrays to understand the basics of the function but can not figure out.
thanks a lot
"How are these x and y values selected? I am working on the small arrays to understand the basics of the function but can not figure out."
The first link I gave you explains that:
is it possible to explain the given expressions? i was working with only 1 and small array. what is the X Y and Z values, which expressions will give me the x and y values in that case? thanks
@Stephen23 could you please explain the problem that I am facing with? with that format contourc(array,level), which values are gonna change with these X Y and Z?

Sign in to comment.

Answers (1)

The documentation doesn't disclose it, but I would guess that it does a kind of 2D bisection algorithm. Sample points are chosen near where Z=level and the area covered by the samples is iteratively contracted to make abs(Z-level) smaller and smaller.

Categories

Products

Release

R2020a

Asked:

on 14 Nov 2023

Commented:

on 16 Nov 2023

Community Treasure Hunt

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

Start Hunting!