plot area between 2 curves, not working

조회 수: 26 (최근 30일)
Paulo
Paulo 2024년 2월 5일
답변: Star Strider 2024년 2월 5일
Hello,
i'm tryng to plot the area betwen two curves, but the shape is not closing and the shading is not apearing. Can someone help me?
x2 = [x fliplr(x)];
inBetween = [curve1 fliplr(curve2)];
figure
hold on
patch(x2, inBetween,[0.7 0.7 0.7]);

답변 (2개)

Voss
Voss 2024년 2월 5일
There is a NaN in each of curve1 and curve2. NaNs make patches unrenderable, so you need to remove the NaNs or replace them with something else. Here I use fillmissing to replace the NaNs.
load data
% each of curve1 and curve2 has 1 non-finite element, which in fact are NaNs
nnz(~isfinite(curve1))
ans = 1
nnz(~isfinite(curve2))
ans = 1
% replace NaNs and make new vectors to use for plotting
curve1_plot = fillmissing(curve1,'nearest');
curve2_plot = fillmissing(curve2,'nearest');
% plot
x2 = [x fliplr(x)];
inBetween = [curve1_plot fliplr(curve2_plot)];
figure
patch(x2, inBetween,[0.7 0.7 0.7]);
% zoom in to see the patch
xlim([0 100])

Star Strider
Star Strider 2024년 2월 5일
The ‘curve’ vectors each have NaN values, and patch will not plot them. Eliminiate them (I did that here with fillmissing) and it works (although it is necessary to restrict at least one axis to see the result).
Try this
load('data.mat')
% whos
curves = [curve1; curve2].';
curves = fillmissing(curves, 'nearest').';
figure
plot(x, curves(1,:))
hold on
plot(x, curves(2,:))
patch([x flip(x)], [curves(1,:) flip(curves(2,:))], [0.7 0.7 0.7], 'EdgeColor','none')
hold off
xlim([0 100])
.

카테고리

Help CenterFile Exchange에서 Propagation and Channel Models에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by