Effacer les filtres
Effacer les filtres

Hi, I have a 150*54 matrix and a table of 18 labels ,and i want to named each 3 column of my matrix(which is 54) by 1 label

2 vues (au cours des 30 derniers jours)
Hi, I have a 150*54 matrix and a table of 18 labels ,and i want to named each 3 column of my matrix(which is 54) by 1 label ,how it possible ? Thanks in advance

Réponse acceptée

Walter Roberson
Walter Roberson le 20 Sep 2017
Is column 3 a numeric index into the label list?
%prepare some data for test purposes
your_labels = {'a', 'and', 'because', 'excessively', 'hamster', 'manager', 'me', 'not', 'obeyed', 'smart', 'some', 'system', 'tall', 'terrified', 'the', 'to', 'told', 'young'}; %18 labels
your_matrix = rand(150, 54);
your_matrix(:,3) = randi(length(your_labels), 150, 1);
%now do the work
V = @(M) M(:);
result = [num2cell(your_matrix(:,1:2),2), V(your_labels(your_matrix(:,3))), num2cell(your_matrix(:,4:end),2)];
Though you might prefer,
result = [V(your_labels(your_matrix(:,3))), num2cell(your_matrix(:,[1:2,4:end]),2)];

Plus de réponses (1)

KL
KL le 19 Sep 2017
your_matrix = rand(150,54);
C = mat2cell(your_matrix,150,repmat(3,1,18));
% your_labels = 1x18 cellarray
T = cell2table(C,'VariableNames',your_labels);
  4 commentaires
ladan hz
ladan hz le 19 Sep 2017
yes you are right im R2011a,what can i do ? :(
KL
KL le 20 Sep 2017
Or just use an array of structs..
your_matrix = rand(150,54);
C = mat2cell(your_matrix,150,repmat(3,1,18));
your_labels = {'a', 'and', 'because', 'excessively', 'hamster', 'manager', 'me', 'not', 'obeyed', 'smart', 'some', 'system', 'tall', 'terrified', 'the', 'to', 'told', 'young'}; %18 labels
for k=1:numel(your_labels)
labelled_data(k).label = your_labels(k);
labelled_data(k).values = C{k};
end

Connectez-vous pour commenter.

Catégories

En savoir plus sur Large Files and Big Data dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by