필터 지우기
필터 지우기

How to Add Border to Single Color Region in pcolor Plot

조회 수: 9 (최근 30일)
Zakir Hussain Shaik
Zakir Hussain Shaik 2024년 3월 4일
답변: Voss 2024년 3월 4일
I'm currently working with a pcolor plot in MATLAB, where the top-right side area is represented by a single color. I'm seeking assistance on how to draw a border around this particular region.
Attached are three figures:
Figure 1: The original pcolor plot.
I want the border coordinates for all '0' values extracted from my matrix, represented as coordinates in xc and yc variables. This will allow me to plot the border over the existing pcolor plot. The desired border appearance is illustrated below:
Figure 2: The plot needed.
The data matrix of the variabel I am plotting looks of the form:
Figure 3: Screenshot data matrix
I have also attached data file for reference.
The code to display the plot:
[X,Y] = meshgrid(1:100,1:10); figure
h = pcolor(X',Y',medianVarianceAll2);
colormap(jet)
colorbar
%% If I obtain xc and yc variables, I should be able to execute:
[X,Y] = meshgrid(1:100,1:10); figure
h = pcolor(X',Y',medianVarianceAll2);
colormap(jet)
colorbar
hold on
plot(xc,yc,'linewidth',2,'r');
I'm looking for guidance on how to identify and outline the single color region in the plot. Any suggestions or code snippets would be greatly appreciated. Thank you in advance for your help!

채택된 답변

Voss
Voss 2024년 3월 4일
load TestData
[m,n] = size(medianVarianceAll2);
[X,Y] = meshgrid(1:m,1:n);
figure
h = pcolor(X',Y',medianVarianceAll2);
colormap(jet)
colorbar
is_zero = medianVarianceAll2.' == 0;
Xz = X(is_zero);
Yz = Y(is_zero);
idx = boundary([Xz,Yz]);
[xc,yc] = stairs(Xz(idx),Yz(idx));
hold on
plot(xc,yc,'r','linewidth',2);

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Formatting and Annotation에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by