Hi, is it possible to assign table variable name based on strings in an array. For example:
colnames={'a' 'b'};
a=[1;2];
b=[3;4];
c=table();
c.colnames{1}=a;
c.colnames{2}=b;
Thank you.

 채택된 답변

James Tursa
James Tursa 2016년 7월 29일

0 개 추천

Do you mean like this:
c.(colnames{1}) = a;
c.(colnames{2}) = b;

추가 답변 (1개)

Steven Lord
Steven Lord 2016년 7월 29일

0 개 추천

Set the VariableNames of the table when you create it.
colnames = {'a' 'b'};
a = [1;2];
b = [3;4];
c = table(a, b, 'VariableNames', colnames)
Or change them later by assigning to the VariableNames property of the table.
newnames = {'Alice', 'Bob'};
c.Properties.VariableNames = newnames

카테고리

도움말 센터File Exchange에서 Tables에 대해 자세히 알아보기

태그

질문:

2016년 7월 29일

댓글:

2016년 7월 30일

Community Treasure Hunt

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

Start Hunting!

Translated by