Permutation based on array indices

8 ビュー (過去 30 日間)
lilly lord
lilly lord 2021 年 2 月 5 日
コメント済み: lilly lord 2021 年 2 月 5 日
Hi. I want to permute elemnts of a row matrix w.rt to anothe matrix of the same dimension. Below is the part of the code but it gives error.
E3 =[4,73,1,76,109,224,199,134,80,253,156,177,166,167,29,48,206,127,99,234,240,93,102,231,12,65,255,78,79,254,94,239,25,52,31,46,98,235,82,251,72,5,2,75,181,152,43,34,233,100,243,90,182,151,145,188,8,69,3,74,35,42,161,172,221,112,63,14,248,85,115,218,108,225,19,58,66,11,173,160,191,142,144,189,28,49,27,50,241,92,184,149,185,148,129,204,60,17,107,226,211,122,21,56,86,247,6,71,20,57,119,214,33,44,0,77,238,95,96,237,9,68,217,116,201,132,200,133,61,16,170,163,197,136,118,215,59,18,154,179,153,180,114,219,124,209,210,123,126,207,117,216,178,155,23,54,194,139,162,171,157,176,87,246,83,250,7,70,213,120,45,32,249,84,26,51,30,47,135,198,159,174,193,140,64,13,53,24,192,141,55,22,183,150,67,10,212,121,40,37,97,236,81,252,143,190,38,39,164,169,101,232,175,158,110,223,128,205,113,220,203,130,91,242,244,89,138,195,105,228,165,168,125,208,202,131,230,103,106,227,111,222,15,62,137,196,41,36,186,147,229,104,88,245,146,187];
X=[0,241,62,150,100,54,97,104,235,252,5,23,255,135,40,57,232,167,102,222,10,233,78,3,162,24,7,130,118,196,13,39,17,151,238,64,136,215,159,254,37,192,63,163,25,133,14,143,9,216,50,73,123,224,207,98,92,227,112,30,33,174,134,198,121,253,15,147,140,124,90,36,157,113,42,206,127,26,60,103,172,244,94,4,72,218,116,248,188,195,101,168,35,182,107,56,219,138,21,86,110,145,217,66,152,111,228,230,81,76,200,156,183,202,45,52,229,84,209,181,65,125,144,142,18,226,82,11,70,186,179,27,109,88,203,249,80,51,245,193,93,87,68,41,204,132,22,2,170,160,69,210,234,239,180,43,237,197,137,191,67,201,115,61,247,139,47,19,44,164,214,29,16,95,165,240,58,146,6,190,213,28,119,74,75,141,131,96,99,129,71,236,48,108,114,85,251,20,128,153,212,177,250,166,242,32,77,8,155,173,117,205,225,79,49,126,171,89,53,55,158,246,223,189,91,148,59,185,46,105,175,220,208,154,199,1,12,122,243,106,176,31,83,34,38,221,169,194,187,211,178,120,231,149,184,161];
E=X(E3);
Error
Array indices must be positive integers or logical values.
Can any one figure out whats the problem.
Both E3 and X are of class double
  2 件のコメント
lilly lord
lilly lord 2021 年 2 月 5 日
When I tried to convert values from double to uint 8 i got the same error.
E3_1=uint8(E3);
X_1=uint8(X);
E=X_1(E3_1);
Joseph van 't Hoff
Joseph van 't Hoff 2021 年 2 月 5 日
it is not a problem that E3 consists of doubles, the problem is that E3(115)=0. Therefore you're trying to access the zeroth element of array X, which doesn't exist (Matlab starts indices at 1)
If you do E3(115)=1 and then E=X(E3) it does work (although I assume what you are trying to do is E3a=E3+1 and then E=X(E3a) )

サインインしてコメントする。

採用された回答

Joseph van 't Hoff
Joseph van 't Hoff 2021 年 2 月 5 日
element 115 of your array E3 is zero, all indices have to be positive integers
  1 件のコメント
lilly lord
lilly lord 2021 年 2 月 5 日
Yes u r rt. thank you

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeElementary Math についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by