Azzera filtri
Azzera filtri

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 visualizzazioni (ultimi 30 giorni)
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

Risposta accettata

Walter Roberson
Walter Roberson il 20 Set 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)];

Più risposte (1)

KL
KL il 19 Set 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 Commenti
KL
KL il 20 Set 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

Accedi per commentare.

Categorie

Scopri di più su Large Files and Big Data in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by