how to allocate elements of a vector into different rows in a matrix, preserving the column order?
이전 댓글 표시
Consider
Z = zeros(4,2);
X = [0.15 , 0.33];
P=[2 3];
I am looking for the simplest form of applying P to X and Z so that I obtain:
Z = [0 0; 0.15 0; 0 0.33; 0 0];
The vector P is a vector of indices that applies to the vector X, and positions the column elements of X in the rows of Z indicated in P. So, the number 0.15 moves Down to row 2, (still in column 1) and the number 0.33 moves Down to row 3 (and column 2);
Of course, this is an example. It will apply to much bigger objects.
Thank you.
Joao Ejarque
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Matrices and Arrays에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!