How to move array data to additional columns based on repeats in a vector or column
이전 댓글 표시
I have an array like A (below) with duplicates in the second column, for example there are three 1's,three 6's and four 7's. What I would like to do is either have a separate array for each block (to include all the multiples) or preferably be able to move the data for the multiples in the 3rd and 4th columns to the same row as the first element but in extra columns I could preallocate for? i have some code to move the duplicates out onto the same row and replace the original data with nans but cannot get them all on one row.
A=[ 1 1 1.0277 0.56932
2 1 1.0426 0.4202
3 1 1.048 0.42017
4 2 1.1466 0.48309
5 6 1.4731 0.4024
6 6 1.5244 0.62436
7 6 1.5295 0.40456
8 7 1.55 0.58695
9 7 1.5658 0.41037
10 7 1.6107 0.4693
11 7 1.6248 0.62088
12 8 1.7182 0.48]
for k=2:size(A)
if A(k,2)==A(k-1,2)
A(k-1,5)=A(k,3)
A(k-1,6)=A(k,4)
A(k,3)=nan
A(k,4)=nan
end
end
Best regards
Steve
채택된 답변
추가 답변 (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!