I want to add binary numbers randomly in a cell array. How to do it?

2 visualizaciones (últimos 30 días)
Muhammad Bin
Muhammad Bin el 28 de Jul. de 2021
Respondida: Johannes Hougaard el 29 de Jul. de 2021
Cell array
  1 comentario
Marcel Kreuzberg
Marcel Kreuzberg el 29 de Jul. de 2021
write a random binary number (max 1024) randomly in a 10x10 cell array:
C{randi(10),randi(10)} = dec2bin(randi(1024))

Iniciar sesión para comentar.

Respuestas (1)

Johannes Hougaard
Johannes Hougaard el 29 de Jul. de 2021
I can't really get the desired output from Marcels comment. Maybe if you add it to a for loop it'll be feasible.
However I think this will do the trick
maxnum = 1024;
rowno = 10;
colno = 9;
C = cellfun(@dec2bin,num2cell(randi(maxnum,rowno,colno)),'UniformOutput',false);

Categorías

Más información sobre Matrices and Arrays 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