How binary Random number generation upto n nodes ?

i was do this
clc;
clear all;
close all;
% Link is (n-1)*node/2
node = 3;
offset = 1;
L = (node-offset)*node/2;
c =2^L;
% Generate c binary values:
r = randi([0, 1], c,L);
disp(r);
output:
0 0 1
1 0 0
1 0 0
1 0 1
1 1 0
1 0 0
0 1 0
0 0 1
but i want
0 0 0
0 0 1
0 1 0
0 1 1
1 0 0
1 0 1
1 1 0
1 1 1
please help me how to generate binary random numbers up to n in order wise

댓글 수: 1

Your current code generates random patterns. But what you want is not random at all ... it is an ordered list. Why do you write you want random output but then show a non-random ordered list as what you want?

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

 채택된 답변

James Tursa
James Tursa 2021년 3월 15일

0 개 추천

Here is how to get your stated desired output, but this is not random at all:
r = dec2bin(0:(2^L-1)) - '0';

댓글 수: 4

I also try this code but upto 7 nodes the numbers. If I enter n=9, the will not come. I want upto n nodes.
James Tursa
James Tursa 2021년 3월 15일
편집: James Tursa 2021년 3월 15일
The memory requirements for generating the complete list of patterns can easily exceed the amount of memory that your computer has. This method is only practical for small numbers. I could suggest that you use logical variables instead of double, but even then if you have such a large list how do you intend to use this downstream in your code? Depending on how involved your downstream processing is, it might take days or weeks or months or years to process all of the individual patterns. You will need a different approach to solving your problem if you have to work with large numbers.
n = 3;
Link=(n*(n-1))/2;
c=2^Link;
NN = toeplitz(Link+1:-1:2)
mask = logical(fliplr(diag(ones(1,Link-1),-1)));
NN(mask) = 1;
for c = 0:2^Link-1
l = bitget(c, NN)
end
the above code i generate all configuration matrix.
i need to generate all paths in this network.
please help me to generate all paths in the network
Jan
Jan 2021년 4월 24일
This is a new question. Please ask it in a new thread.

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

제품

릴리스

R2016a

질문:

2021년 3월 15일

댓글:

Jan
2021년 4월 24일

Community Treasure Hunt

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

Start Hunting!

Translated by