table variable name based on array

11 vues (au cours des 30 derniers jours)
Azura Hashim
Azura Hashim le 29 Juil 2016
Commenté : Azura Hashim le 30 Juil 2016
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.

Réponse acceptée

James Tursa
James Tursa le 29 Juil 2016
Do you mean like this:
c.(colnames{1}) = a;
c.(colnames{2}) = b;
  1 commentaire
Azura Hashim
Azura Hashim le 30 Juil 2016
Works perfectly thanks.

Connectez-vous pour commenter.

Plus de réponses (1)

Steven Lord
Steven Lord le 29 Juil 2016
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
  1 commentaire
Azura Hashim
Azura Hashim le 30 Juil 2016
This works too thanks.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Tables dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by