plot area between 2 curves, not working
26 views (last 30 days)
Show older comments
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]);
0 Comments
Answers (2)
Voss
on 5 Feb 2024
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))
nnz(~isfinite(curve2))
% 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])
0 Comments
Star Strider
on 5 Feb 2024
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])
.
0 Comments
See Also
Categories
Find more on Propagation and Channel Models in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
