Fill between two curves is not working

16 visualizaciones (últimos 30 días)
Sim
Sim el 31 de Ag. de 2020
Comentada: Sim el 31 de Ag. de 2020
Hi, I would need to fill up the area between two curves, and I tried to use the function fill as follows:
fill([x fliplr(x)],[curve2 fliplr(curve1)],'r')
However, I get this plot:
Any idea on how to fix it?
The inputs are:
x = [1:167]';
curve1 = [0.673996610286411
0.673673251337359
0.673415708189219
0.673217628041518
0.673072658093783
0.672974445545541
0.672916637596318
0.672892881445642
0.672896824293039
0.672922113338036
0.67296239578016
0.673011318818937
0.673062529653894
0.673109675484559
0.673146403510457
0.673166360931115
0.673163194946061
0.673130552754822
0.673062081556923
0.672951428551891
0.672792240939255
0.672583514699266
0.672345640935088
0.672104359530608
0.671885410369716
0.671714533336301
0.671617468314251
0.671619955187455
0.671747733839802
0.672026544155181
0.67246565118383
0.673008420641381
0.673581743409818
0.674112510371122
0.674527612407275
0.674753940400259
0.674718385232058
0.674347837784653
0.673569188940025
0.672309329580159
0.670495150587034
0.668113291382176
0.665389385545275
0.662608815195564
0.660056962452274
0.658019209434639
0.656780938261889
0.656627531053258
0.657714102816945
0.659674700117009
0.662013102406479
0.664233089138384
0.665838439765749
0.666332933741602
0.665220350518972
0.662147683851062
0.657334784691779
0.651144718295209
0.643940549915434
0.63608534480654
0.627942168222611
0.61987408541773
0.612132703790435
0.604523799317075
0.596741690118449
0.58848069431536
0.579435130028609
0.569299315378996
0.557767568487323
0.544711705519161
0.530713534819153
0.516532362776713
0.502927495781255
0.490658240222192
0.480483902488938
0.473163788970907
0.469457206057512
0.469890106166702
0.474055025830568
0.481311147609734
0.491017654064828
0.502533727756473
0.515218551245297
0.528431307091925
0.541531177856983
0.553877346101096
0.56482899438489
0.573882914265223
0.581086333283881
0.586624087978881
0.590681014888241
0.593441950549979
0.595091731502113
0.595815194282661
0.595797175429641
0.595218240981186
0.594241874975899
0.593027290952496
0.591733702449696
0.590520323006215
0.589546366160771
0.588971045452083
0.588953574418867
0.589653166599841
0.591229035533723
0.593840394759231
0.597565138943005
0.602155887263384
0.607283940026628
0.612620597538999
0.617837160106758
0.622604928036167
0.626595201633486
0.629558708460915
0.631563885104397
0.632758595405817
0.633290703207056
0.633308072349997
0.632958566676522
0.632390050028514
0.631750386247856
0.631187439176429
0.630849072656117
0.630851152682596
0.631181553866717
0.631796152973129
0.632650826766476
0.633701452011405
0.634903905472563
0.636214063914597
0.637587804102151
0.638981002799873
0.640349536772409
0.641649282784406
0.64283611760051
0.643865917985367
0.644707012443729
0.64537753644077
0.645908077181772
0.646329221872014
0.646671557716777
0.646965671921341
0.647242151690986
0.647531584230992
0.647864556746639
0.648264977818572
0.64873004152888
0.649250263335021
0.64981615869445
0.65041824306462
0.651047031902987
0.651693040667007
0.652346784814134
0.652998779801824
0.653639541087531
0.65425958412871
0.654849424382818
0.655399577307308
0.655900558359636
0.656342882997257
0.656717066677625
0.657013624858197
0.657223072996427
0.65733592654977
0.657342700975681
0.657233911731616
0.657000074275028];
curve2 = [0.672772576702148
0.672366853836992
0.671866640834829
0.67127815023829
0.670607594590004
0.6698611864326
0.669045138308709
0.668165662760959
0.667228972331981
0.666241279564404
0.665208797000857
0.664137737183971
0.663034312656375
0.661904735960698
0.66075521963957
0.659591976235622
0.658421218291481
0.657249158349779
0.656082008953144
0.654925982644206
0.653794448058048
0.652729398199563
0.651779982166097
0.650995349054996
0.650424647963607
0.650117027989274
0.650121638229345
0.650487627781166
0.651264145742082
0.65250034120944
0.654245363280585
0.656495636729907
0.65903668903996
0.661601323370342
0.663922342880652
0.665732550730486
0.666764750079442
0.666751744087119
0.665520664779371
0.663275959647084
0.6603164050474
0.656940777337462
0.653447852874412
0.650136408015393
0.647305219117548
0.645253062538019
0.644278714633949
0.64468095176248
0.646758550280755
0.650547128468748
0.655029672297751
0.658926009661891
0.66095596845529
0.659839376572075
0.654296061906368
0.643045852352296
0.624808575803982
0.598810171196179
0.566301021626156
0.52903762123181
0.488776464151038
0.447274044521737
0.406286856481804
0.367571394169136
0.33288415172163
0.303981623277182
0.282190940683338
0.267121786626229
0.257954481501636
0.253869345705336
0.254046699633111
0.25766686368074
0.263910158244002
0.271983520713369
0.281200356458082
0.290900687842075
0.300424537229282
0.309111926983635
0.316302879469068
0.321337417049515
0.323741109218905
0.323781713991152
0.321912536510165
0.318586881919852
0.314258055364123
0.309379361986887
0.304404106932054
0.299785595343532
0.29597713236523
0.293432023141058
0.292489460685004
0.293032189491368
0.294828841924531
0.297648050348872
0.301258447128771
0.305428664628609
0.309927335212765
0.314523091245618
0.318984565091549
0.323080389114938
0.326579195680164
0.329249617151608
0.330942039655212
0.331833864363177
0.332184246209265
0.332252340127239
0.332297301050863
0.332578283913898
0.33335444365011
0.334884935193259
0.337428913477111
0.341245533435426
0.346530720545872
0.353227482461721
0.36121559738015
0.370374843498336
0.380584999013454
0.39172584212268
0.403677151023192
0.416318703912164
0.429530278986773
0.443191654444197
0.457182608481609
0.471382919296188
0.485672365085109
0.499930724045548
0.514037774374681
0.527863503990741
0.541238739696186
0.553984518014528
0.565921875469282
0.576871848583961
0.586655473882078
0.595093787887147
0.602007827122682
0.607269681917838
0.61095565782434
0.613193114199558
0.614109410400857
0.613831905785607
0.612487959711174
0.610204931534926
0.607110180614231
0.603331066306458
0.598994947968972
0.594229184959143
0.589161136634337
0.583930417972631
0.578725666434929
0.573747775102845
0.569197637057991
0.565276145381981
0.562184193156428
0.560122673462945
0.559292479383144
0.559894503998639
0.562129640391043
0.566198781641968
0.572302820833029
0.580642651045837
0.591419165362006
0.604833256863149
0.621085818630879
0.64037774374681
0.662909925292553
0.688883256349722
0.71849862999993];
  2 comentarios
Adam Danz
Adam Danz el 31 de Ag. de 2020
Editada: Adam Danz el 31 de Ag. de 2020
Your data are column vectors and you've got two mistakes related to that.
  1. fliplr does nothing with a column vector.
  2. you want to vertically concatenate them, not horizontally.
Sim
Sim el 31 de Ag. de 2020
Thanks a lot Adam! Yes, my silly mistake... :)

Iniciar sesión para comentar.

Respuesta aceptada

Star Strider
Star Strider el 31 de Ag. de 2020
Use the patch function instead:
figure
patch([x; flipud(x)], [curve1; flipud(curve2)], 'r')
producing:
.
  4 comentarios
Bruno Luong
Bruno Luong el 31 de Ag. de 2020
As Adam Danz rightly pointed out PATCH has nothing to do with fixing the issue, rather formatting the verticall data.
fill([x; flipud(x)], [curve1; flipud(curve2)], 'r')
works as well.
Sim
Sim el 31 de Ag. de 2020
Thanks both Star and Bruno :) ...Yes, it was my stupid mistake :)

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Lighting, Transparency, and Shading en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by