I am dividing 8bit binary value to two 4 bits values. How not to get "{}" these bars with my output

1 visualización (últimos 30 días)
I am using the function
result=dec2bin(I(i,j),8);
value = mat2cell(result,1,[4,4]);
Now I want to store the "value" in some variable but I get it in {'1001'} form and I need it in simple 1001 or '1001' form with the curly I cannot perform any function.
I want to convert the value '1001' to decimal but the function "bi2de()" do not work on it.
thanks

Respuesta aceptada

MUHAMMAD ISLAM
MUHAMMAD ISLAM el 30 de Sept. de 2021
I got the answer the function give output as value{1} = '1001' and value{2}='1100'. I was storing it as i= value(1) so it used to store it as i={'1001'} but when I tried i=value{1} so it stored correctly i = '1001'

Más respuestas (1)

Dave B
Dave B el 30 de Sept. de 2021
Editada: Dave B el 30 de Sept. de 2021
The function mat2cell converts to a cell array, which is shown with {} and which you can retrieve the values with the same {}
result=dec2bin(58,8)
result = '00111010'
value = mat2cell(result,1,[4 4])
value = 1×2 cell array
{'0011'} {'1010'}
value{1}
ans = '0011'
bin2dec(value{1})
ans = 3
value{2}
ans = '1010'
bin2dec(value{2})
ans = 10
You can also apply a function to several cells at once using cellfun:
cellfun(@bin2dec, value)
ans = 1×2
3 10

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by