separet value in one colone to many colone
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
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 ];
0 Kommentare
Antworten (1)
Ameer Hamza
am 30 Dez. 2020
Bearbeitet: Ameer Hamza
am 30 Dez. 2020
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 Kommentare
Image Analyst
am 30 Dez. 2020
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. 🙂
Siehe auch
Kategorien
Mehr zu Descriptive Statistics finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!