Convert Column vector into matrix
2 ビュー (過去 30 日間)
古いコメントを表示
I have a 1158x1 column vector. The elements of the vector has values from 1 to 256. Each value is repeated for a maximum of 10 times. Some values are repeated even for less than 10 times. I want to convert into 10X256 matrix. I want all the 1's to be in 1st column, 2's in the second column and so on. To make it a proper matrix, fill rest of the values with zeros. The column vector is attached. How can I do that?
2 件のコメント
Stephan
2020 年 11 月 30 日
What about the missing values? For example 141 and 144 have no occurence - wha about the corresponding columns?
採用された回答
その他の回答 (1 件)
Nicholas Brophy
2020 年 11 月 30 日
function [arr]=pankajSort(vec)
arr=zeros(10,length(vec));
for i= 1:length(vec)
mask= i==vec;
TRUES = sum(mask,'all');
for ii=1:TRUES
arr(ii,i)=i;
end
end
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Author Block Masks についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!