Write values from 3 columns into one column

조회 수: 2 (최근 30일)
Vespi
Vespi 2016년 3월 13일
답변: Star Strider 2016년 3월 13일
I would like to merge 3 column values into one column as can be done in execl. For example, I have column values C1-C3 and I want to create column C4 as shown below:
C1 C2 C3 C4
1 2 3 123
4 5 7 457
19 4 25 19425
I tried A(:), but my values are not written as shown in C4 above. Can this be done in MatLab?

채택된 답변

Star Strider
Star Strider 2016년 3월 13일
The only way I can think of to do it is:
A = [1 2 3
4 5 7
19 4 25];
Out = str2num(sprintf([repmat('%d',1,size(A,2)) '\n'], A'))
Out =
123
457
19425
If you want to concatenate ‘Out’ with ‘A’:
Anew = [A Out]
Anew =
1 2 3 123
4 5 7 457
19 4 25 19425

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by