color region in the plot based on the values
조회 수: 6 (최근 30일)
이전 댓글 표시
Hi,
In the attached array, I need to color the region based on whenever A(:,2) is greater than 5. I tried yregion,seems this will work only in 2023.
댓글 수: 2
Dyuman Joshi
2023년 11월 2일
Which version of MATLAB are you using?
If you want an output similar to what yregion provies, what is the upper limit for the region?
If it is not similar to that, what is the expected output? A visual example would be helpful.
Dyuman Joshi
2023년 11월 2일
You forgot to provide the end values -
Red color from 5 to what? Inf?
Similarly, green color from what to 5? -Inf?
And I suppose the x-limits should be the range of the x values i.e. A(:,1)?
채택된 답변
Star Strider
2023년 11월 2일
Try this —
LD = load('matlab.mat');
A = LD.A
thrshld = 5;
Lv = A(:,2) > thrshld;
idx1 = find(Lv);
idx2 = idx1(diff([0; idx1]) == 1);
% [x1,x2] = bounds(idx2)
idx2 = min(idx2) : max(idx2);
figure
plot(A(:,1), A(:,2))
hold on
patch([A(idx2,1); flip(A(idx2,1))], [thrshld+zeros(size(A(idx2,2))); flip(A(idx2,2))], 'r', 'FaceAlpha',0.5, 'EdgeColor','none')
patch([A(idx2,1); flip(A(idx2,1))], [min(ylim)+zeros(size(A(idx2,2))); thrshld+zeros(size(A(idx2,2)))], 'g', 'FaceAlpha',0.5, 'EdgeColor','none')
hold off
grid
.
댓글 수: 3
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Data Distribution Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!