sharing of numbers in the matrix

2 Ansichten (letzte 30 Tage)
Prabha Kumaresan
Prabha Kumaresan am 15 Dez. 2017
Bearbeitet: Andrei Bobrov am 15 Dez. 2017
If
A=[0.1 0 0.2 0 0 0 0 0;0 0 0 0.3 0.4 0 0 0;0 0.5 0 0 0 0 0 0.6;0 0 0 0 0 0.7 0.8 0]
I want to have
B=[0.1 0 0.2 0.3 0.4 0 0 0;0.1 0 0.2 0.3 0.4 0 0 0;0 0.5 0 0 0 0 0.7 0.8 0.6;0 0.5 0 0 0 0 0.7 0.8 0.6]
could anyone tell me how to get it?
  6 Kommentare
Prabha Kumaresan
Prabha Kumaresan am 15 Dez. 2017
A is a matrix of subcarrier allocation to users,where rows denote users and columns denote subcarriers.B(2,2) is 0 which means subcarrier is not being used by user1 and user2.
Jos (10584)
Jos (10584) am 15 Dez. 2017
I am completely lost ... Stephen and Andrei, the floor is yours

Melden Sie sich an, um zu kommentieren.

Antworten (2)

Stephen23
Stephen23 am 15 Dez. 2017
Bearbeitet: Stephen23 am 15 Dez. 2017
Solution to your original question:
>> reshape(repmat(max(reshape(A,2,[])),2,1),size(A))
ans =
0.10000 0.00000 0.20000 0.30000 0.40000 0.00000 0.00000 0.00000
0.10000 0.00000 0.20000 0.30000 0.40000 0.00000 0.00000 0.00000
0.00000 0.50000 0.00000 0.00000 0.00000 0.70000 0.80000 0.60000
0.00000 0.50000 0.00000 0.00000 0.00000 0.70000 0.80000 0.60000
Solution to your later comment:
>> repmat(reshape(max(reshape(A,2,[])),2,[]),2,1)
ans =
0.10000 0.00000 0.20000 0.30000 0.40000 0.00000 0.00000 0.00000
0.00000 0.50000 0.00000 0.00000 0.00000 0.70000 0.80000 0.60000
0.10000 0.00000 0.20000 0.30000 0.40000 0.00000 0.00000 0.00000
0.00000 0.50000 0.00000 0.00000 0.00000 0.70000 0.80000 0.60000

Andrei Bobrov
Andrei Bobrov am 15 Dez. 2017
Bearbeitet: Andrei Bobrov am 15 Dez. 2017
out = repelem(squeeze(max(permute(reshape(A,2,2,[]),[1,3,2]))),1,2)';
or
out = A;
[ii,jj] = find(A);
t = rem(ii,2);
out(sub2ind(size(out),ii - ~t + t,jj)) = A(A>0);
  3 Kommentare
Prabha Kumaresan
Prabha Kumaresan am 15 Dez. 2017
If i need to have B such that B =
0.1000 0.5000 0.2000 0 0 0 0 0.6000
0 0 0 0.3000 0.4000 0.7000 0.8000 0
0.1000 0.5000 0.2000 0 0 0 0 0.6000
0 0 0 0.3000 0.4000 0.7000 0.8000 0
how it can be done.
Andrei Bobrov
Andrei Bobrov am 15 Dez. 2017
Bearbeitet: Andrei Bobrov am 15 Dez. 2017
See Stephen's answer (first part).
B = reshape(repmat(max(reshape(A,2,2,[]),[],2),1,2),size(A));
or
[ii,jj] = find(A);
B = A;
B(sub2ind(size(A),rem(ii + 1,4)+1,jj)) = A(A>0);

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu MATLAB finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by