How to identify if the interval values of a closed contour are greater or lesser than a certain value
3 ビュー (過去 30 日間)
古いコメントを表示
Hello. I aim to determine whether the internal values of a closed contour line are greater or lesser than a predefined value. I have been attempting to do this using the contourf function. This allows you to create a figure that presents the inside of a closed contour as a filled in colour - please see image below.
This can be done with the code below, where the cut off value that I would like to know if the internal values are greater or lesser than is 2:
figure
k = contourf(p, [2 2]);
The output matrix, k, of the contourf function exports the coordinate data of the contour lines. It also includes markers, which denote the function value of the contour line and the number of coordinate data points in that contour line. If the contour is closed, the first and last point will have the same value. See image below for the plot of the output matrix, k, including marker points.
The contours can be isolated using the marker points, so that they can be seperated into indervidual data sets within a cell array. I have done this using the algorithm below:
length = numel(k(1,:));
index_i = k(2,1);
index_t_old = index_i + 1;
n_contours = 1;
A{n_contours} = k(:,2:index_t_old);
while index_t_old < length
n_contours = n_contours + 1;
index_i = k(2,index_t_old+1);
index_t_new = index_t_old + index_i + 1;
A{n_contours} = k(: , index_t_old + 2 : index_t_new);
index_t_old = index_t_new;
end
Plotting this and tracking the number of each data point gives you a figure excluding the markers, presented as such below, using the code also attached below:
figure
for j = 1:n_contours
plot(A{j}(1,:),A{j}(2,:),'xk');
hold on
for ii = 1:numel(A{j}(1,:));
text(A{j}(1,ii),A{j}(2,ii),num2str(ii),'FontSize',4,'Color','r')
end
end
How can I, with the data provided from contourf, or with another MATLAB function, be able to tell if the internal data of a closed contour is greater or lesser than a predefined value, in a robust manner? I aim for this to be able to work for any mathematical function (not just peaks), that could have differing number of closed boundaries, of any shape or size. The contour lines could represent lines that enclose data values that are greater or lesser than the cut-off values defined with the contour function (the value was 2 in this case).
Thank you for any help that can be offered.
0 件のコメント
回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Contour Plots についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!