how to create a matrix in matlab?
Afficher commentaires plus anciens
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
Réponse acceptée
Plus de réponses (2)
M = dec2bin(0:7)-'0'
[L23, L13, L12] = ndgrid(0:1);
L12 = L12(:); L13 = L13(:); L23 = L23(:);
table(L12, L13, L23)
15 commentaires
ankanna
le 16 Mar 2021
ankanna
le 16 Mar 2021
Walter Roberson
le 16 Mar 2021
I do not understand your pseudocode.
Are you trying to create an algorithm for link assignment between communicating users?
Walter Roberson
le 16 Mar 2021
Modifié(e) : Walter Roberson
le 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
le 20 Mar 2021
Walter Roberson
le 20 Mar 2021
Modifié(e) : Walter Roberson
le 20 Mar 2021
for n = 0:2^nodes-1
out(:,:,n+1)= bitget(n, NN);
end
ankanna
le 20 Mar 2021
ankanna
le 20 Mar 2021
Modifié(e) : Walter Roberson
le 24 Mar 2021
ankanna
le 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
le 2 Avr 2021
ankanna
le 11 Avr 2021
Walter Roberson
le 11 Avr 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
le 20 Avr 2021
Catégories
En savoir plus sur Memory Usage dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
