create a matrix with numbers from vector
古いコメントを表示
i have a vector as
v = [ 1 1 1 2 2 2 3 3 4]
i wanted to create a new matrix as
M = [
1 1 1 0 0 0 0 0 0;
0 0 0 1 1 1 0 0 0;
0 0 0 0 0 0 1 1 0;
0 0 0 0 0 0 0 0 1];
how to do it?
採用された回答
その他の回答 (2 件)
madhan ravi
2019 年 2 月 13 日
Simpler:
M = +(v==unique(v).')
2 件のコメント
Stephen23
2019 年 2 月 13 日
+1 very tidy. I like that.
madhan ravi
2019 年 2 月 13 日
Thank you!
KSSV
2019 年 2 月 13 日
N = zeros(3,3,3) ;
for i = 1:3
N(i,:,i) = 1 ;
end
M = reshape(N,3,[])
カテゴリ
ヘルプ センター および File Exchange で Dynamic System Models についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!