MATLAB: Convert type while keeping values MATLABtype How to convert the type of an array while keeping the value of all elements? For example, A = [200 150 30] in uint16 to B = [200 150 30] in uint8. Best Answer A = uint16([200 150 30]) ;B = uint8(A) ;class(A)class(B) Related SolutionsMATLAB: Converting binary to decimal Why are you using uint16 when you have a negative number?????Anyway,...S = -5;Cw1=dec2bin(typecast(int16(S),'uint16'),15)S_recovered = bin2dec(Cw1)maxUint16 = intmax('uint16')maxInt16 = intmax('int16')if S_recovered > maxInt16 S_recovered = int16(S_recovered - double(maxUint16) - 1)endS_recovered will be -5 as a signed 16 bit integer, which is what I assume you want. MATLAB: Check a variable is a symbolic or a double syms a b=10 class(a) class(b) Related QuestionHow to compare each element of a matrix with a numberKeeping track of variablesStr2num conversion for vectorsHow to extract data from table keeping while keeping the floating point
Best Answer