"index exceeds array bounds " error. Don't know whats wrong

12 ビュー (過去 30 日間)
Paulina Maldonado
Paulina Maldonado 2018 年 6 月 22 日
回答済み: Walter Roberson 2018 年 6 月 22 日
Having trouble fixing this issue. Please help
for i = 1:1:4800
% Because in MATLAB/Octave indexing starts from 1
if image(i) < 255
image(i) = image(i) + 1;
end
alphaLSH = uint32(bitshift(255, 24));
redLSH = uint32(bitshift(paletteR(image(i)), 16));
greenLSH = uint32(bitshift(paletteG(image(i)), 8));
blueLSH = uint32(bitshift(paletteB(image(i)), 0));
image(i) = typecast(bitor(bitor(alphaLSH, redLSH), bitor(greenLSH, blueLSH)), ...
'int32');
end
Command window shows:
Index exceeds array bounds.
Error in matlab_example_create_image3 (line 116)
redLSH = uint32(bitshift(paletteR(image(i)), 16));
  1 件のコメント
Walter Roberson
Walter Roberson 2018 年 6 月 22 日
We do not know what size() of your palette* variables is.
What class is your image array when you start?

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

回答 (1 件)

Walter Roberson
Walter Roberson 2018 年 6 月 22 日
It looks to me as if you are re-arranging bytes. You should look at using byteswap(). Or you should typecast() to uint8, reshape to 4 x N, use indexing to re-arrange the rows, then typecast() back to uint32.

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by