How to read columns from matlab with different number of rows

조회 수: 3 (최근 30일)
José Javier Rubio Rubio
José Javier Rubio Rubio 2020년 12월 2일
댓글: José Javier Rubio Rubio 2020년 12월 2일
I need to read all the numeric data from several columns of twelve excels. I'm referring specifically that I'd like to code a loop where I could save in a matrix all the data. For example, I create an array called "energia_activa" and there I have to save the column C of each excel. The problem is that each excel has a different number of rows so when I am reading them with a loop an error related to the dimmensions of the matrix in the left side and right side appears. How can I solve it?
On the other hand, one of the column of each excel I have to import has in several of the excels empty cells so when I am reading them an error appears as well. I'd be very grateful if you could help me.
Thank you in advance.
meses = ["enero 2019.xlsx","febrero 2019.xlsx", "marzo 2019.xlsx", "abril 2019.xlsx", "mayo 2019.xlsx", "junio 2019.xlsx", "julio 2019.xlsx", "agosto 2019.xlsx", "septiembre 2019.xlsx", "octubre 2019.xlsx", "noviembre 2019.xlsx", "diciembre 2019.xlsx"];
%ENERGÍA ACTIVA
dimensiones = zeros(1,12);
for i=1:12
dimensiones(1,i)=size(xlsread(meses(i),'C:C'),1);
end
energia_activa = zeros(max(dimensiones),12);
for i=1:dimensiones(i)
energia_activa(:,i)=xlsread(meses(i),'C:C')
end
  댓글 수: 2
Mathieu NOE
Mathieu NOE 2020년 12월 2일
hello José
could you share also the xlsx files ?
tx
José Javier Rubio Rubio
José Javier Rubio Rubio 2020년 12월 2일
Hi Mathieu,
Of course. I must keep their names and the columns which I am interested in are C, D, F and G. Column D has several empty cells in some of the excels and it brings some error. Moreover, column F is alphanumeric.
Thank you.

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

답변 (0개)

카테고리

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

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by