separet value in one colone to many colone

조회 수: 1 (최근 30일)
alize beemiel
alize beemiel 2020년 12월 30일
댓글: Image Analyst 2020년 12월 30일
hi, every one !
i have matrix witn n line row
mtx= [1 101;
2 011;
3 111;
4 110;
5 110];
% and so on (n rows )
and i want to have this to disjoin value (one colone 2 ) to sep are in 2 and 3 and 4 colone like this
mtx = [1 1 0 1;
2 0 1 1;
3 1 1 1;
4 1 1 0;
5 1 1 0 ];

답변 (1개)

Ameer Hamza
Ameer Hamza 2020년 12월 30일
편집: Ameer Hamza 2020년 12월 30일
Try this
mtx= [1 101;
2 011;
3 111;
4 110;
5 110];
cols = reshape(sprintf('%03d', mtx(:,2)), 3, []).'-'0';
out = [mtx(:,1) cols]
Result
>> out
out =
1 1 0 1
2 0 1 1
3 1 1 1
4 1 1 0
5 1 1 0
  댓글 수: 3
Ameer Hamza
Ameer Hamza 2020년 12월 30일
I am glad to be of help!!!
Image Analyst
Image Analyst 2020년 12월 30일
alize, can you please click the "Accept this answer" link to give Ameer credit in terms of "reputation points" for helping you with this clever answer? Thanks in advance. 🙂

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

카테고리

Help CenterFile Exchange에서 Spline Postprocessing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by