how can i put a label for columns in an array?
조회 수: 2 (최근 30일)
이전 댓글 표시
i have a vector as follows
x=[1 5 8 0 6 1]
i want result to be
x1 x2 x3 x4 x5 x6
1 5 8 0 6 1
how can i do it??
댓글 수: 0
답변 (2개)
David Sanchez
2014년 8월 7일
x=[1 5 8 0 6 1];
C=cell(2,length(x));
for k=1:length(x)
C{1,k} = sprintf('x%g',k);
C{2,k} = x(k);
end
disp(C)
'x1' 'x2' 'x3' 'x4' 'x5' 'x6'
[ 1] [ 5] [ 8] [ 0] [ 6] [ 1]
댓글 수: 0
Azzi Abdelmalek
2014년 8월 7일
x=[1 5 8 0 6 1]
header=genvarname(repmat({'x'},1,size(x,2)),'x')
out=[header;num2cell(x)]
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Argument Definitions에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!