how to create a matrix in matlab?
Show older comments
L12 L13 L23
0 0 0
0 0 1
0 1 0
0 1 1
1 0 0
1 0 1
1 1 0
1 1 1
how to create a matrix
Accepted Answer
More Answers (2)
M = dec2bin(0:7)-'0'
[L23, L13, L12] = ndgrid(0:1);
L12 = L12(:); L13 = L13(:); L23 = L23(:);
table(L12, L13, L23)
15 Comments
ankanna
on 16 Mar 2021
ankanna
on 16 Mar 2021
Walter Roberson
on 16 Mar 2021
I do not understand your pseudocode.
Are you trying to create an algorithm for link assignment between communicating users?
Walter Roberson
on 16 Mar 2021
Edited: Walter Roberson
on 16 Mar 2021
%input is n, scalar integer starting from 0
[
bitget(n,4), bitget(n,3), bitget(n,2);
bitget(n,3), bitget(n,4), bitget(n,1);
bitget(n,2), bitget(n,1), bitget(n,4);
]
Which can be written in terms of
NN = [4, 3, 2; 3 4 1; 2 1 4]
bitget(n,NN)
Why that particular NN? Well, for the case of node = 3, it is
NN = toeplitz(node+1:-1:2);
mask = logical(fliplr(diag(ones(1,node-1),-1)));
NN(mask) = 1;
out = bitget(n, NN)
It is likely that this would have to change for node = 4, but you would need to give more information about the pattern for 4 for me to predict.
node = 3;
NN = toeplitz(node+1:-1:2);
mask = logical(fliplr(diag(ones(1,node-1),-1)));
NN(mask) = 1;
for n = 0:7
out = bitget(n, NN)
end
ankanna
on 20 Mar 2021
Walter Roberson
on 20 Mar 2021
Edited: Walter Roberson
on 20 Mar 2021
for n = 0:2^nodes-1
out(:,:,n+1)= bitget(n, NN);
end
ankanna
on 20 Mar 2021
ankanna
on 20 Mar 2021
Edited: Walter Roberson
on 24 Mar 2021
ankanna
on 20 Mar 2021
format long g
nodes = 10;
lamda = 0.7;
bits = dec2bin(0:2^nodes-1)-'0';
nl = sum(bits,2);
nu = nodes-nl;
P = lamda.^nl .* (1-lamda).^nu;
P(1:20)
[minP, minidx] = min(P)
bits(minidx,:)
[maxP, maxidx] = max(P)
bits(maxidx,:)
histogram(P)
ankanna
on 2 Apr 2021
ankanna
on 11 Apr 2021
Walter Roberson
on 11 Apr 2021
That code will never do what you want it to do, and it cannot be fixed.
Your source is a paper that is wrong. You need to get corrections from the authors of the paper.
ankanna
on 20 Apr 2021
Categories
Find more on Memory Usage in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!