problem with typecast command
30 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I have a array of dimensions 199*8180 of uint 8 type. I am using typecast command to convert it into unit16 type but I am getting an error message. The message is
Error using typecast The first input argument must be a vector.
can someone please help me with this.
Regards, Jatin
0 comentarios
Respuestas (2)
Image Analyst
el 16 de Mayo de 2013
Try cast() instead of typecast().
image16 = cast(image8, 'uint16');
or simply
image16 = uint16(image8);
Multiply image8 by 256 before casting if you want to brighten it.
1 comentario
Shashank Prasanna
el 16 de Mayo de 2013
IA, cast simple changes the datatype represented in ML where as typecast changes the underlying representation without changing the data. This is useful say when a hardware returns uint16 through a serial connection (but the data is actually double), you would need to typecast it. cast function here would simply change class uint16 to class double keeping the same data. The ambiguity arises from the nomenclature.
Here is an excerpt from the documentation of typecast:
typecast is different from the MATLAB® cast function in that it does not alter the input data. typecast always returns the same number of bytes in the output Y as were in the input X.
Shashank Prasanna
el 16 de Mayo de 2013
typecast only takes scalars or vectors. If you have a matrix you can convert it into a vector from a matrix and then use typecast
>> datauint8 = data(:);
>> datauint16 = typecast(datauint8,'uint16');
>> datamat = reshape(datauint16,199,8180);
0 comentarios
Ver también
Categorías
Más información sobre String Parsing 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!