How to read a column with numbers and words from several Excel?

1 回表示 (過去 30 日間)
José Javier Rubio Rubio
José Javier Rubio Rubio 2020 年 11 月 19 日
回答済み: Ananthi Jegan 2020 年 11 月 19 日
I would like to read a column from several excel. The data in the column can be: 1P, 2P, 3P, 4P, 5P, 6P. I know [~,txtData] but only I know how to use it in order to read from one excel not from several. Could you help me to figure it out? For reading numeric columns from several excel I usually use the code below with readmatrix but I don't know how to read columns with numbers and words.
Thanks in advance.
range='C:D';
% get list of .xlsx files
d=dir('2019_*.xlsx'); % 'list' is built-in MATLAB function -- don't alias it...
numFiles = length(d);
energy=zeros(numFiles,2); % allocate for the energy sums
for k = 1:numFiles
energy(k,:)=sum(readmatrix(d(k).name,'Range',range,'NumHeaderLines',1),'omitnan');
end

回答 (1 件)

Ananthi Jegan
Ananthi Jegan 2020 年 11 月 19 日
You have to replace "readmatrix" with "readtable" to read columns with both numbers and strings from excel
readtable(d(k).name,'Range',range,'NumHeaderLines',1)

カテゴリ

Help Center および File ExchangeSpreadsheets についてさらに検索

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by