필터 지우기
필터 지우기

Saving column headers to vector

조회 수: 26 (최근 30일)
Amanda Eriksson
Amanda Eriksson 2022년 2월 1일
댓글: Simon Chan 2022년 2월 1일
I have a xlsx file which contains a set of rows and columns (26x13) but the set of columns may vary. So for each column there is a header in the xlsx, and I uses readtable to open the xlsx.
I have now divided so I get the data out from each column, but how do I save the header name? I want to be able to save the header name into some sort of string/vector so that when displaying the data it simply can be refered to that header(set of data).
files.path = '.'; % Absolute/relative path to where the selected file exist
[filename path] = uigetfile([files.path '*.txt; *.TAC; *.xlsx;'], 'Choose TAC file of .xlxs format');
t = readtable(filename,'VariableNamingRule','preserve');
A = table2array(t);
num = cellfun(@str2num,A);
[numrows, numcol] = size(num);
for i = 1:numcol
roi.names{i} = t{}; % Here I want to loop over the column headers and save down the header name into a string/vector
end

채택된 답변

Simon Chan
Simon Chan 2022년 2월 1일
You may retrieve the header name in a cell array as follows:
t.Properties.VariableNames
  댓글 수: 2
Amanda Eriksson
Amanda Eriksson 2022년 2월 1일
THANK YOU. so so much, thank you :))))
Simon Chan
Simon Chan 2022년 2월 1일
You may accept the answer if you find it useful. Thank you.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by