필터 지우기
필터 지우기

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 (최근 30일)
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

채택된 답변

Walter Roberson
Walter Roberson 2017년 9월 20일
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)];

추가 답변 (1개)

KL
KL 2017년 9월 19일
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
KL
KL 2017년 9월 20일
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

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Large Files and Big Data에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by