how can i apply 1 of k coding scheme on 2D MATRIX

1 回表示 (過去 30 日間)
GHUFRAN AHMAD KHAN
GHUFRAN AHMAD KHAN 2018 年 9 月 12 日
コメント済み: GHUFRAN AHMAD KHAN 2018 年 9 月 12 日
the order of matrix can be any number except 1.
  3 件のコメント
GHUFRAN AHMAD KHAN
GHUFRAN AHMAD KHAN 2018 年 9 月 12 日
編集済み: GHUFRAN AHMAD KHAN 2018 年 9 月 12 日
the sum of each row should be 1 and each entry should be 0 or 1 is called 1 of k coding scheme and below are one question solution.
>> C = [1,1,2,3,1,3,2];
>> R = 1:numel(C);
>> A = zeros(numel(C),max(C));
>> A(sub2ind(size(A),R,C)) = 1
A = 1 0 0; 1 0 0; 0 1 0; 0 0 1; 1 0 0; 0 0 1; 0 1 0
Rik
Rik 2018 年 9 月 12 日
So you already have working code? Then what is your question?

サインインしてコメントする。

採用された回答

Andrei Bobrov
Andrei Bobrov 2018 年 9 月 12 日
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 件のコメント
Andrei Bobrov
Andrei Bobrov 2018 年 9 月 12 日
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;
GHUFRAN AHMAD KHAN
GHUFRAN AHMAD KHAN 2018 年 9 月 12 日
here this message is showing when i am seeing the value of the out variable.
_ Cannot display summaries of variables with more than 524288 elements._

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeWhos についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by