Error: array indices must be positive integers

1 visualización (últimos 30 días)
LucasH
LucasH el 30 de Sept. de 2021
Editada: LucasH el 30 de Sept. de 2021
Hello, I'm new here, I have a question. When I try to execute the attached code I get the error message: "Array indices must be positive integers or logical values. Error in Untitled233>g2l (line 12) B1=xxx(B)/5.4426; Error in Untitled233 (line 2) testv=g2l(cast(y1,'uint8'));"
It says that the array indices must be integers, but I use numbers from an uint8 image as the indices, so why does it say they are not integers? Besides that, the error seems to indicate that the first time the error is encoutered is in line 12 with 'B1=xxx(B)/5.4426', would that mean that only the values from B are not integers? Why wouldn't B consist of integers but would R and G?
Thanks in advance.
y1=imresize(webread('http://www.cs.albany.edu/~xypan/research/img/Kodak/kodim21.png'),[360,360]);
testv=g2l(cast(y1,'uint8'));
function outputluminance=g2l(grayinput)
zzz=[-0.0245800000000000 -0.0244955200000000 -0.0242097032878820 -0.0237010252078527 -0.0229568980231368 -0.0219680915258250 -0.0207272363214161 -0.0192281623989676 -0.0174655430224352 -0.0154346793888438 -0.0131313598444584 -0.0105517624996849 -0.00769238491066181 -0.00454999155923436 -0.00112157353868598 0.00259568309890936 0.00660442267160571 0.0109071404674750 0.0155061997345663 0.0204038458656814 0.0256022183690718 0.0311033610673987 0.0369092308614722 0.0430217053185676 0.0494425892885454 0.0561736207086544 0.0632164757257502 0.0705727732399610 0.0782440789546231 0.0862319090022280 0.0945377332041541 0.103162978012386 0.112109029173695 0.121377234150487 0.130968904327364 0.140885317028231 0.151127717365240 0.161697319937970 0.172595310398732 0.183822846897865 0.195381061421106 0.207271061029623 0.219493929012043 0.232050725956684 0.244942490751279 0.258170241516644 0.271734976480063 0.285637674793499 0.299879297301252 0.314460787261179 0.329383071023190 0.344647058668355 0.360253644611665 0.376203708171158 0.392498114105913 0.409137713125147 0.426123342370490 0.443455825873292 0.461135974988689 0.479164588807978 0.497542454550756 0.516270347938120 0.535349033548163 0.554779265154860 0.574561786051386 0.594697329358811 0.615186618321057 0.636030366586914 0.657229278479888 0.678784049256561 0.700695365354130 0.722963904627711 0.745590336577981 0.768575322569685 0.791919516041475 0.815623562707569 0.839688100751625 0.864113761013251 0.888901167167509 0.914050935897777 0.939563677062283 0.965439993854624 0.991680482958569 1.01828573469740 1.04525633317806 1.07259285643035 1.10029587654139 1.12836595978556 1.15680366675016 1.18560955245689 1.21478416647946 1.24432805305737 1.27424175120610 1.30452579482386 1.33518071279504 1.36620702909037 1.39760526286424 1.42937592854890 1.46151953594595 1.49403659031518 1.52692759246068 1.56019303881465 1.59383342151862 1.62784922850256 1.66224094356165 1.69700904643092 1.73215401285797 1.76767631467354 1.80357641986029 1.83985479261971 1.87651189343728 1.91354817914587 1.95096410298754 1.98876011467377 2.02693666044407 2.06549418312319 2.10443312217687 2.14375391376618 2.18345699080055 2.22354278298949 2.26401171689307 2.30486421597120 2.34610070063168 2.38772158827717 2.42972729335105 2.47211822738219 2.51489479902873 2.55805741412082 2.60160647570237 2.64554238407197 2.68986553682275 2.73457632888146 2.77967515254665 2.82516239752605 2.87103845097305 2.91730369752255 2.96395851932589 3.01100329608511 3.05843840508653 3.10626422123355 3.15448111707882 3.20308946285570 3.25208962650918 3.30148197372605 3.35126686796452 3.40144467048328 3.45201574036990 3.50298043456876 3.55433910790838 3.60609211312819 3.65823980090490 3.71078251987820 3.76372061667612 3.81705443593980 3.87078432034789 3.92491061064038 3.97943364564211 4.03435376228573 4.08967129563437 4.14538657890374 4.20149994348397 4.25801171896097 4.31492223313747 4.37223181205361 4.42994078000725 4.48804945957386 4.54655817162610 4.60546723535305 4.66477696827908 4.72448768628247 4.78459970361361 4.84511333291300 4.90602888522886 4.96734667003451 5.02906699524539 5.09119016723588 5.15371649085578 5.21664626944656 5.27997980485731 5.34371739746048 5.40785934616731 5.47240594844306 5.53735750032197 5.60271429642200 5.66847662995934 5.73464479276267 5.80121907528721 5.86819976662858 5.93558715453640 6.00338152542773 6.07158316440024 6.14019235524525 6.20920938046057 6.27863452126304 6.34846805760105 6.41871026816675 6.48936143040812 6.56042182054088 6.63189171356018 6.70377138325217 6.77606110220539 6.84876114182194 6.92187177232861 6.99539326278772 7.06932588110788 7.14366989405462 7.21842556726076 7.29359316523679 7.36917295138099 7.44516518798942 7.52157013626586 7.59838805633149 7.67561920723454 7.75326384695976 7.83132223243776 7.90979461955426 7.98868126315916 8.06798241707555 8.14769833410857 8.22782926605413 8.30837546370757 8.38933717687216 8.47071465436751 8.55250814403789 8.63471789276038 8.71734414645299 8.80038715008262 8.88384714767298 8.96772438231231 9.05201909616113 9.13673153045975 9.22186192553585 9.30741052081181 9.39337755481204 9.47976326517021 9.56656788863637 9.65379166108396 9.74143481751682 9.82949759207603 9.91798021804667 10.0068829278646 10.0962059531230 10.1859495245790 10.2761138721601 10.3666992249706 10.4577058112978 10.5491338586183 10.6409835936044 10.7332552421298 10.8259490292760 10.9190651793380 11.0126039158301 11.1065654614923 11.2009500382952 11.2957578674465 11.3909891693961];
yyy=[-0.0796829000000000 -0.0786317204654614 -0.0767488068841287 -0.0739824347315323 -0.0702944940828806 -0.0656544536738020 -0.0600366825408970 -0.0534190037233320 -0.0457818176021774 -0.0371075276319722 -0.0273801424216835 -0.0165849879801204 -0.00470849250723404 0.00826197899984288 0.0223382547491259 0.0375314602894821 0.0538521032835721 0.0713101434865733 0.0899150512188669 0.109675856749951 0.130601192403904 0.152699328764633 0.175978206045685 0.200445461458084 0.226108453236396 0.252974281851643 0.281049808838462 0.310341673585212 0.340856308373877 0.372599951907496 0.405578661523566 0.439798324260164 0.475264666915687 0.511983265222012 0.549959552233459 0.589198826019437 0.629706256736655 0.671486893146606 0.714545668635508 0.758887406786688 0.804516826549173 0.851438547041051 0.899657092021597 0.949176894062288 1.00000229844347 1.05213756680045 1.10558688054038 1.16035434404887 1.21644398770350 1.27385977070962 1.33260558377221 1.39268525161653 1.45410253536863 1.51686113480631 1.58096469048966 1.64641678577988 1.71322094875398 1.78138065402268 1.85089932445784 1.92178033283546 1.99402700339973 2.06764261335320 2.14263039427761 2.21899353348976 2.29673517533631 2.37585842243124 2.45636633683925 2.53826194120827 2.62154821985410 2.70622811979965 2.79230455177157 2.87978039115638 2.96865847891839 3.05894162248149 3.15063259657653 3.24373414405633 3.33824897667973 3.43417977586639 3.53152919342373 3.63029985224743 3.73049434699675 3.83211524474582 3.93516508561217 4.03964638336340 4.14556162600319 4.25291327633737 4.36170377252117 4.47193552858834 4.58361093496302 4.69673235895502 4.81130214523935 4.92732261632059 5.04479607298277 5.16372479472530 5.28411104018560 5.40595704754904 5.52926503494644 5.65403720083998 5.78027572439766 5.90798276585696 6.03716046687808 6.16781095088709 6.29993632340943 6.43353867239413 6.56862006852907 6.70518256554760 6.84322820052692 6.98275899417837 7.12377695113004 7.26628406020201 7.41028229467424 7.55577361254773 7.70275995679883 7.85124325562719 8.00122542269742 8.15270835737471 8.30569394495470 8.46018405688761 8.61618055099697 8.77368527169313 8.93270005018151 9.09322670466612 9.25526704054812 9.41882285061982 9.58389591525422 9.75048800259016 9.91860086871323 10.0882362578327 10.2593959024543 10.4320815235494 10.6062948307203 10.7820375223618 10.9593112858196 11.1381177975451 11.3184587232464 11.5003357180371 11.6837504265814 11.8687044832358 12.0551995121884 12.2432371275954 12.4328189337142 12.6239465250345 12.8166214864063 13.0108453931653 13.2066198112562 13.4039462973531 13.6028263989780 13.8032616546164 14.0052535938315 14.2088037373751 14.4139135972977 14.6205846770550 14.8288184716140 15.0386164675556 15.2499801431764 15.4629109685883 15.6774104058159 15.8934799088924 16.1111209239541 16.3303348893325 16.5511232356452 16.7734873858855 16.9974287555093 17.2229487525218 17.4500487775617 17.6787302239846 17.9089944779443 18.1408429184735 18.3742769175623 18.6092978402361 18.8459070446317 19.0841058820722 19.3238956971409 19.5652778277536 19.8082536052303 20.0528243543648 20.2989913934943 20.5467560345667 20.7961195832080 21.0470833387875 21.2996485944827 21.5538166373432 21.8095887483529 22.0669662024920 22.3259502687976 22.5865422104234 22.8487432846990 23.1125547431870 23.3779778317411 23.6450137905614 23.9136638542504 24.1839292518672 24.4558112069812 24.7293109377254 25.0044296568479 25.2811685717640 25.5595288846061 25.8395117922744 26.1211184864852 26.4043501538200 26.6892079757729 26.9756931287980 27.2638067843554 27.5535501089575 27.8449242642137 28.1379304068748 28.4325696888774 28.7288432573867 29.0267522548393 29.3262978189855 29.6274810829303 29.9303031751749 30.2347652196568 30.5408683357896 30.8486136385028 31.1580022382797 31.4690352411965 31.7817137489599 32.0960388589441 32.4120116642276 32.7296332536301 33.0489047117474 33.3698271189878 33.6924015516061 34.0166290817389 34.3425107774379 34.6700477027040 34.9992409175204 35.3300914778853 35.6626004358442 35.9967688395220 36.3325977331546 36.6700881571197 37.0092411479682 37.3500577384540 37.6925389575646 38.0366858305502 38.3824993789535 38.7299806206385 39.0791305698190 39.4299502370872 39.7824406294412 40.1366027503129 40.4924375995955 40.8499461736698 41.2091294654316 41.5699884643175 41.9325241563313 42.2967375240693 42.6626295467464 43.0302012002206 43.3994534570182 43.7703872863584 44.1430036541774 44.5173035231527 44.8932878527266];
xxx=[-0.0342534000000000 -0.0334578170665024 -0.0322881537738871 -0.0307818057192417 -0.0289625503336234 -0.0268475430399854 -0.0244500530781136 -0.0217808123228827 -0.0188487758506525 -0.0156615909940929 -0.0122259059142904 -0.00854758278827010 -0.00463185088111556 -0.000483419930091218 0.00389343368148974 0.00849480000000000 0.0133170825604131 0.0183569558355660 0.0236113305590749 0.0290773251180938 0.0347522416967607 0.0406335461882799 0.0467188511328477 0.0530059011115412 0.0594925601533037 0.0661768008068246 0.0730566946006336 0.0801304036694003 0.0873961733667188 0.0948523257176751 0.102497253590546 0.110329415487693 0.118347330872327 0.126549575961260 0.134934779924676 0.143501621442897 0.152248825577534 0.161175160920490 0.170279436989402 0.179560501842391 0.189017239888577 0.198648569873851 0.208453443024017 0.218430841329587 0.228579775958421 0.238899285784038 0.249388436018807 0.260046316942456 0.270872042717389 0.281864750283220 0.293023598323730 0.304347766300176 0.315836453545471 0.327488878414337 0.339304277484970 0.351281904808231 0.363421031200707 0.375720943578368 0.388180944327814 0.400800350712387 0.413578494310666 0.426514720485069 0.439608387878489 0.452858867937059 0.466265544457298 0.479827813156043 0.493545081261678 0.507416767125310 0.521442299850635 0.535621118941339 0.549952673964958 0.564436424232213 0.579071838490895 0.593858394633451 0.608795579417484 0.623882888198427 0.639119824673702 0.654505900637739 0.670040635747249 0.685723557296204 0.701554200000000 0.717532105788327 0.733656823606279 0.749927909223297 0.766344925049532 0.782907439959266 0.799615029121033 0.816467273834115 0.833463761371104 0.850604084826238 0.867887842969238 0.885314640104385 0.902884085934599 0.920595795430284 0.938449388702733 0.956444490881873 0.974580731998172 0.992857746868518 1.01127517498589 1.02983266041268 1.04852985167747 1.06736640167518 1.08634196757038 1.10545621070368 1.12470879650101 1.14409939438584 1.16362767769392 1.18329332359081 1.20309601299173 1.22303543048396 1.24311126425140 1.26332320600146 1.28367095089401 1.30415419747244 1.32477264759658 1.34552600637767 1.36641398211508 1.38743628623475 1.40859263322940 1.42988274060041 1.45130632880116 1.47286312118198 1.49455284393657 1.51637522604984 1.53832999924707 1.56041689794445 1.58263565920088 1.60498602267102 1.62746773055950 1.65008052757636 1.67282416089349 1.69569838010229 1.71870293717226 1.74183758641070 1.76510208442329 1.78849619007571 1.81201966445616 1.83567227083871 1.85945377464760 1.88336394342233 1.90740254678355 1.93156935639982 1.95586414595499 1.98028669111648 2.00483676950416 2.02951416065999 2.05431864601833 2.07925000887688 2.10430803436829 2.12949250943239 2.15480322278897 2.18023996491127 2.20580252799987 2.23149070595730 2.25730429436305 2.28324309044922 2.30930689307659 2.33549550271123 2.36180872140161 2.38824635275612 2.41480820192108 2.44149407555925 2.46830378182865 2.49523713036192 2.52229393224599 2.54947400000229 2.57677714756717 2.60420319027284 2.63175194482863 2.65942322930262 2.68721686310358 2.71513266696334 2.74317046291942 2.77133007429799 2.79961132569721 2.82801404297083 2.85653805321206 2.88518318473786 2.91394926707336 2.94283613093671 2.97184360822405 3.00097153199495 3.03021973645788 3.05958805695614 3.08907632995392 3.11868439302263 3.14841208482749 3.17825924511437 3.20822571469679 3.23831133544317 3.26851595026440 3.29883940310143 3.32928153891324 3.35984220366492 3.39052124431601 3.42131850880897 3.45223384605788 3.48326710593733 3.51441813927150 3.54568679782337 3.57707293428414 3.60857640226287 3.64019705627617 3.67193475173817 3.70378934495057 3.73576069309291 3.76784865421295 3.80005308721721 3.83237385186166 3.86481080874259 3.89736381928754 3.93003274574648 3.96281745118301 3.99571779946579 4.02873365526003 4.06186488401915 4.09511135197659 4.12847292613763 4.16194947427151 4.19554086490348 4.22924696730708 4.26306765149655 4.29700278821927 4.33105224894833 4.36521590587528 4.39949363190292 4.43388530063817 4.46839078638513 4.50300996413814 4.53774270957504 4.57258889905041 4.60754840958904 4.64262111887935 4.67780690526701 4.71310564774861 4.74851722596540 4.78404152019716 4.81967841135609 4.85542778098086 4.89128951123069 4.92726348487950 4.96334958531020 4.99954769650899 5.03585770305979 5.07227949013869 5.10881294350854 5.14545794951352 5.18221439507392 5.21908216768081 5.25606115539095 5.29315124682165 5.33035233114574 5.36766429808663 5.40508703791338 5.44262044143586 5.48026440000000];
[R,G,B]=imsplit(grayinput);
R1=zzz(R)/11.2958;
G1=yyy(G)/44.5173;
B1=xxx(B)/5.4426;
outputluminance=cat(3,R1,G1,B1);
end

Respuesta aceptada

Jan
Jan el 30 de Sept. de 2021
You can use the debugger to find the cause of the problem. Let Matlab stop when the error occurs:
dbstop if error
Type this in the command window and run the code again. When it stops at the error, examine the value of the index:
unique(B)
The values can be integers, but not "positive integers", if they contain the value 0, which is not a valid index.
  1 comentario
LucasH
LucasH el 30 de Sept. de 2021
Editada: LucasH el 30 de Sept. de 2021
Thank you very much, this was the problem indeed. I solved it by using B+1 instead of B.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Matrix Indexing en Help Center y File Exchange.

Productos


Versión

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by