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
Stephan 2020년 11월 30일
What about the missing values? For example 141 and 144 have no occurence - wha about the corresponding columns?
pankaj singh
pankaj singh 2020년 11월 30일
those columns can be filled by zeros.

댓글을 달려면 로그인하십시오.

 채택된 답변

Matt J
Matt J 2020년 11월 30일
편집: Matt J 2020년 11월 30일

1 개 추천

H=histcounts(coln,1:257);
result=((1:10).'<=H).*(1:256);

추가 답변 (1개)

Nicholas Brophy
Nicholas Brophy 2020년 11월 30일

0 개 추천

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

카테고리

도움말 센터File Exchange에서 MATLAB에 대해 자세히 알아보기

태그

질문:

2020년 11월 30일

답변:

2020년 11월 30일

Community Treasure Hunt

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

Start Hunting!

Translated by