1D array to 2D array positions

6 ビュー (過去 30 日間)
Eduardo Santos
Eduardo Santos 2019 年 4 月 30 日
編集済み: James Tursa 2019 年 4 月 30 日
I would like to 'convert' a 1D array to a 2D matrix considering the value inside the array as:
A =
1 3 4 4 3
B =
0 0 0 0 0
0 0 1 1 0
0 1 0 0 1
0 0 0 0 0
1 0 0 0 0
Can you suggest a very fast way to do that?
The row number is fixed at 5 here (a known value).

採用された回答

James Tursa
James Tursa 2019 年 4 月 30 日
編集済み: James Tursa 2019 年 4 月 30 日
n = 5;
B = zeros(n,size(A,2));
B(sub2ind(size(B),n+1-A,1:size(A,2))) = 1;

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by