Borrar filtros
Borrar filtros

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 visualizaciones (últimos 30 días)
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

Respuesta aceptada

Walter Roberson
Walter Roberson el 20 de Sept. de 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)];

Más respuestas (1)

KL
KL el 19 de Sept. de 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 comentarios
KL
KL el 20 de Sept. de 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

Iniciar sesión para comentar.

Categorías

Más información sobre Large Files and Big Data en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by