"index exceeds array bounds " error. Don't know whats wrong
12 views (last 30 days)
Show older comments
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 Comment
Walter Roberson
on 22 Jun 2018
We do not know what size() of your palette* variables is.
What class is your image array when you start?
Answers (1)
Walter Roberson
on 22 Jun 2018
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.
0 Comments
See Also
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!