How to fill in the area under the curve

조회 수: 6 (최근 30일)
Meghan
Meghan 2025년 7월 3일
댓글: Star Strider 2025년 7월 3일
I'm trying to fill in the area under the curve from 0-0.21 in one color and 0.21-0.45 in another color.
clc
clear all;
x=[0.00
0.01
0.02
0.03
0.04
0.05
0.06
0.07
0.08
0.09
0.10
0.11
0.12
0.13
0.14
0.15
0.16
0.17
0.18
0.19
0.20
0.21
0.22
0.23
0.24
0.25
0.26
0.27
0.28
0.29
0.3
0.31
0.32
0.33
0.34
0.35
0.36
0.37
0.38
0.39
0.4
0.41
0.42
0.43
0.44
0.45
0.46
0.47
];
r=[322.7337814 % this is 1/r
326.4298381
330.3538959
334.5184218
338.9371002
343.6249656
348.598554
353.8760759
359.4776157
365.4253608
371.7438663
378.4603625
385.6051117
393.2118255
401.3181536
409.9662594
419.2035004
429.0832367
439.6657964
451.0196342
463.2227305
476.3642911
490.5468243
505.8886991
522.5273178
540.6230829
560.364401
581.9740526
605.7173855
631.9129697
660.9466231
693.2901197
729.5265142
770.3849808
816.7896168
869.9292081
931.3592715
1003.155249
1088.149497
1190.310914
1315.378513
1471.972025
1673.658647
1943.097228
2321.186314
2890.040873
3842.399615
5762.514434
];
figure;
hold on;
plot(x,r,'r')
xlabel('x (conversion fraction)')
ylabel('1/r (kgcat*hr/kgmolEB)')
grid on;
hold off;
W=trapz(x,r);
FA0=613.212;
porosity=0.45;
rho_bulk=2145.27*(1-porosity);
V=FA0*0.454*W/rho_bulk

채택된 답변

Star Strider
Star Strider 2025년 7월 3일
Perhaps something like this --
clc
clear all;
x=[0.00
0.01
0.02
0.03
0.04
0.05
0.06
0.07
0.08
0.09
0.10
0.11
0.12
0.13
0.14
0.15
0.16
0.17
0.18
0.19
0.20
0.21
0.22
0.23
0.24
0.25
0.26
0.27
0.28
0.29
0.3
0.31
0.32
0.33
0.34
0.35
0.36
0.37
0.38
0.39
0.4
0.41
0.42
0.43
0.44
0.45
0.46
0.47
];
r=[322.7337814 % this is 1/r
326.4298381
330.3538959
334.5184218
338.9371002
343.6249656
348.598554
353.8760759
359.4776157
365.4253608
371.7438663
378.4603625
385.6051117
393.2118255
401.3181536
409.9662594
419.2035004
429.0832367
439.6657964
451.0196342
463.2227305
476.3642911
490.5468243
505.8886991
522.5273178
540.6230829
560.364401
581.9740526
605.7173855
631.9129697
660.9466231
693.2901197
729.5265142
770.3849808
816.7896168
869.9292081
931.3592715
1003.155249
1088.149497
1190.310914
1315.378513
1471.972025
1673.658647
1943.097228
2321.186314
2890.040873
3842.399615
5762.514434
];
Lv1 = x <= 0.21;
Lv2 = x >= 0.21;
figure;
hold on;
plot(x,r,'r')
patch([x(Lv1); flip(x(Lv1))], [zeros(size(x(Lv1))); flip(r(Lv1))], 'g', FaceAlpha=0.5, EdgeColor='none')
patch([x(Lv2); flip(x(Lv2))], [zeros(size(x(Lv2))); flip(r(Lv2))], 'r', FaceAlpha=0.5, EdgeColor='none')
xlabel('x (conversion fraction)')
ylabel('1/r (kgcat*hr/kgmolEB)')
grid on;
hold off;
W=trapz(x,r);
FA0=613.212;
porosity=0.45;
rho_bulk=2145.27*(1-porosity);
V=FA0*0.454*W/rho_bulk
V = 93.9412
.
  댓글 수: 2
Meghan
Meghan 2025년 7월 3일
Thank you!
Star Strider
Star Strider 2025년 7월 3일
As always, my pleasure!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Red에 대해 자세히 알아보기

제품


릴리스

R2024b

Community Treasure Hunt

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

Start Hunting!

Translated by