how to vertically cascade a string vector and a numerica matrix

조회 수: 3 (최근 30일)
Tina Zhao
Tina Zhao 2016년 3월 23일
댓글: Tina Zhao 2016년 3월 23일
a={'time','channel1','channel2','channel3'}; b=[ 1 2 3 5; 4 2 6 7; 8 5 1 9; 3 2 4 6; 7 6 0 8]; how to vertically cascade the two, so the first row is a, and b has the same column number (4)?

채택된 답변

Steven Lord
Steven Lord 2016년 3월 23일
Consider creating a table using the contents of the cell array as the variable names and the matrix as the data.
  댓글 수: 1
Tina Zhao
Tina Zhao 2016년 3월 23일
I tried T=array2table(b,'VariableNames',a) and got the following time channel1 channel2 channel3 __ ______ ______ ______
1 2 3 5
4 2 6 7
8 5 1 9
3 2 4 6
7 6 0 8

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

추가 답변 (1개)

Guillaume
Guillaume 2016년 3월 23일
편집: Guillaume 2016년 3월 23일
If tables as per Steven Lord's suggestion don't work for you then:
c = [a; num2cell(b)]
I'd recommend going with a table though.
  댓글 수: 1
Tina Zhao
Tina Zhao 2016년 3월 23일
c = [a; num2cell(b)]
c =
'time' 'channel1' 'channel2' 'channel3'
[ 1] [ 2] [ 3] [ 5]
[ 4] [ 2] [ 6] [ 7]
[ 8] [ 5] [ 1] [ 9]
[ 3] [ 2] [ 4] [ 6]
[ 7] [ 6] [ 0] [ 8]
looks a little weird, Thanks!
I'm creating a big data for someone, who requested the name be put on top, I didn't know it's not straightforward.

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

카테고리

Help CenterFile Exchange에서 Genomics and Next Generation Sequencing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by