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

조회 수: 4 (최근 30일)
Muhammad Bin
Muhammad Bin 2021년 7월 28일
답변: Johannes Hougaard 2021년 7월 29일
Cell array
  댓글 수: 1
Marcel Kreuzberg
Marcel Kreuzberg 2021년 7월 29일
write a random binary number (max 1024) randomly in a 10x10 cell array:
C{randi(10),randi(10)} = dec2bin(randi(1024))

댓글을 달려면 로그인하십시오.

답변 (1개)

Johannes Hougaard
Johannes Hougaard 2021년 7월 29일
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);

카테고리

Help CenterFile Exchange에서 Direct Search에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by