how can i apply 1 of k coding scheme on 2D MATRIX
1 view (last 30 days)
Show older comments
GHUFRAN AHMAD KHAN
on 12 Sep 2018
Commented: GHUFRAN AHMAD KHAN
on 12 Sep 2018
the order of matrix can be any number except 1.
3 Comments
Accepted Answer
Andrei Bobrov
on 12 Sep 2018
C = randi([1,3],2,4)
[m,n] = size(C);
k = max(C(:));
out = zeros(n,k,m);
[ii,kk] = ndgrid(1:m,1:n);
out(sub2ind([n,k,m],kk(:),C(:),ii(:))) = 1
5 Comments
Andrei Bobrov
on 12 Sep 2018
use
C = A + 1;
[m,n] = size(C);
k = max(C(:));
out = zeros(n,k,m);
[ii,kk] = ndgrid(1:m,1:n);
out(sub2ind([n,k,m],kk(:),C(:),ii(:))) = 1;
More Answers (0)
See Also
Categories
Find more on Logical 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!