Subscripted dimension mismatch error dec2hex

7 visualizaciones (últimos 30 días)
Panda
Panda el 13 de Abr. de 2016
Editada: Panda el 13 de Abr. de 2016
Hello
I searched regarding this error but still could not resolve it. I am using the following code:
function[hexoutput] = hexaoutput(colordata)
[row col] = size(colordata);
hexoutput=zeros(row,col);
for i=1:row
for j=1:col
hexoutput(i,j) = dec2hex(colordata(i,j),6);
end
end
end
I am getting the subscripted dim mismatch error. But this is how we loop through a matrix. I am confused. Any help would be great. Thanks.

Respuesta aceptada

Walter Roberson
Walter Roberson el 13 de Abr. de 2016
dec2hex(SOMETHING,6) is going to return 6 (or more) characters. You then try to store those 6 characters into a single numeric array location. Remember, hex is represented as character, but zeros() is numeric, so you are using the wrong datatype for your output array and you are not allowing for the fact that each output needs multiple characters.
  3 comentarios
Walter Roberson
Walter Roberson el 13 de Abr. de 2016
Consider using sprintf('0x%06x', colordata(i,j))
Panda
Panda el 13 de Abr. de 2016
Editada: Panda el 13 de Abr. de 2016
Brother you are simply great!! :) :D Thank you so much!

Iniciar sesión para comentar.

Más respuestas (1)

Roger Stafford
Roger Stafford el 13 de Abr. de 2016
The dec2hex(colordata(i,j),6) quantity is a string of at least six hex characters, and yet your are attempting to place it in a single element of hexoutput. It won't fit. You'll have to make hexoutput bigger! Maybe you'd like to make it three-dimensional.
  1 comentario
Panda
Panda el 13 de Abr. de 2016
Same ans as above sir...understood my mistake. Thanks

Iniciar sesión para comentar.

Categorías

Más información sobre Resizing and Reshaping Matrices en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by