how to create a matrix in matlab?

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

 采纳的回答

Your question is not clear. If you have those 3 arrays:
L12 = [0 0 0 0 1 1 1 1];
L13 = [0 0 1 1 0 0 1 1];
L23 = [0 1 0 1 0 1 0 1];
Matrix = [ L12; L13; L23]
or
Matrix = [ L12; L13; L23 ]'
depending or your needs

更多回答(2 个)

M = dec2bin(0:7)-'0'
M = 8×3
0 0 0 0 0 1 0 1 0 0 1 1 1 0 0 1 0 1 1 1 0 1 1 1
[L23, L13, L12] = ndgrid(0:1);
L12 = L12(:); L13 = L13(:); L23 = L23(:);
table(L12, L13, L23)
ans = 8×3 table
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

15 个评论

how to generate (S - T) path?
for i = 1,2,...,n
for j = i+1,...,n
test - select random number from uniform distribution between (0,1)
if (test<=;λ∩ni = 1nj = 1) then Li,j = 1
else; Li,j = 0
Lj,i = Li,j
L - load Li,j and Lj,i into the matrix L
how to generate code by using this algorithm. please help me to generate code for link status
I do not understand your pseudocode.
Are you trying to create an algorithm for link assignment between communicating users?
%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
out = 3×3
0 0 0 0 0 0 0 0 0
out = 3×3
0 0 0 0 0 1 0 1 0
out = 3×3
0 0 1 0 0 0 1 0 0
out = 3×3
0 0 1 0 0 1 1 1 0
out = 3×3
0 1 0 1 0 0 0 0 0
out = 3×3
0 1 0 1 0 1 0 1 0
out = 3×3
0 1 1 1 0 0 1 0 0
out = 3×3
0 1 1 1 0 1 1 1 0
how to put this topologies in matrix
for n = 0:2^nodes-1
out(:,:,n+1)= bitget(n, NN);
end
NN = toeplitz(node+1:-1:2);
mask = logical(fliplr(diag(ones(1,node-1),-1)));
NN(mask) = 1;
can you please explain this logic
and explain what the logic is used
clear explanation please
n = 4;
L=(n-1)*n/2;
c = 2^L-1;
LN = 4
NN = toeplitz(LN+1:-1:2);
mask = logical(fliplr(diag(ones(1,LN-1),-1)));
NN(mask) = 1;
for n = 0:c
out = bitget(n, NN)
end
output :
out =
1 1 1 1
1 1 1 1
1 1 1 1
1 1 1 1
but i want this diagnol matrix upto n nodes
0 1 1 1
1 0 1 1
1 1 0 1
1 1 1 0
probability of existence of a topology is given by
P(alfak=1) = lamda^nl*(1-lamda)^nu
Where
lamda = probability of link existence = 0.7
nl = linked nodes and
nu = unlinked nodes
now we take 0 0 0
p(alfak=1) =(0.7)^0*(1-0.7)^3
=0.027
0 0 1
p(alfak=1)=(0.7)^1*(1-0.7)^2
= 0.063
0 1 0 and 1 0 0 also sme because only one linked
p(alfak=1)=(0.7)^1*(1-0.7)^2
= 0.063
0 11, 1 0 1, 1 1 0
p(alfak=1)=(0.7)^2*(1-0.7)^1
= 0.147
1 1 1
p(alfak=1)=(0.7)^3*(1-0.7)^0
= 0.343
output will
L12 L13 L23 p(alfak=1)
___ ___ ___ _______
0 0 0 0.027
0 0 1 0.063
0 1 0 0.063
0 1 1 0.147
1 0 0 0.063
1 0 1 0.147
1 1 0 0.147
1 1 1 0.343
i need to generate above matrix
please help me to generate the code
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)
ans = 20×1
5.90490000000001e-06 1.37781e-05 1.37781e-05 3.21489e-05 1.37781e-05 3.21489e-05 3.21489e-05 7.50141000000001e-05 1.37781e-05 3.21489e-05
[minP, minidx] = min(P)
minP =
5.90490000000001e-06
minidx =
1
bits(minidx,:)
ans = 1×10
0 0 0 0 0 0 0 0 0 0
[maxP, maxidx] = max(P)
maxP =
0.0282475249
maxidx =
1024
bits(maxidx,:)
ans = 1×10
1 1 1 1 1 1 1 1 1 1
histogram(P)
how to give reliability that is ri = 0.9?
please help me to generate code
n = 3;ri=0.9; lamda = 0.7;
L=(n*(n-1))/2;
c=2^L;
l=zeros(n,n);
for i = 1:n
for j = i+1:n
test = unifrnd(0,1)
if test<=ri
ni=1
else
ni=0
if ni == 1
if (test<=lamda/n(i)==1./n(j)==1)
l(i,j) = 1;
else
l(i,j) = 0
end
l(j,i) = l(i,j)
end
L = [l(i,j);l(j,i)]
end
end
end
after this code how to add source-destination and two terminal reliability. please help to generate this code.
Source-destination procedure:
Initialize:
source = 1
destination = n
if ni = 1 then lamdasource = 1
for hop = 1,2,...,n-1
for i = 1; ... , n
if lamdai = 1
for j = 1; 2 ..., n
if lij = 1; then lamdaj = 1
else lamdaj = 0
if lamdadestination = 1; then path = 1
else; path = 0
These procedures are used to generate the following MAWN simulation approach, where Q is the number of runs in the simulation.
Calculation of 2TR m:
for q = 1,2,...,Q
Simulate Network --->Lq
Find Path->pathq
2TR m = (Summation with limits Q and q=1 (pathq))/Q
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.
node = 3; ri=0.9;
L=(node*(node-1))/2;
configuration = dec2bin(0:(2^L-1))-'0';
alfak=configuration;
source node=1; destination node=3;
m = Limit on intermediate node;
2TR(alfak) == ri^m;
how to calculate two terminal reliability.
alfak Path 2TR(alfak)
1 r1r3 0.81
2 r1r3 0.81
3 r1r2r3 0.729
4 r1r3 0.81
5 None 0.00
6 r1r3 0.81
7 None 0.00
8 None 0.00
please help me to generate above and i want that 2terminal reliability at output.

请先登录,再进行评论。

类别

帮助中心File Exchange 中查找有关 Memory Usage 的更多信息

产品

版本

R2016a

Community Treasure Hunt

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

Start Hunting!

Translated by