필터 지우기
필터 지우기

1D array to 2D array positions

조회 수: 1 (최근 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 CenterFile Exchange에서 Data Types에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by