0

I want to read E columns of every excel files which do not have equal dimensions and put them into a n*m dimensional array. I used a function named as getAllFiles to obtain all files in a directory. I found the function in this link: How to get all files under a specific directory in MATLAB?. Here's my code:

fileList =  getAllFiles('C:\Users\asus\Network\econimi\S&P500\P1')

for i=1:length(fileList)
    A(i,:)=xlsread(fileList{i},'E:E');
end

I see following error as soon as it puts the data of the first file:

??? Subscripted assignment dimension
mismatch.
Community
  • 1
  • 1

1 Answers1

0

Output of xlsread function is a Matrix or a Vector (depending on your xls data). When you use A(i,:)=xlsread(fileList{i},'E:E'); you are saying to MATLAB that you want to assign a Matrix or a Vector to i th row and all ( : ) columns of A Matrix. Since A Matrix does not exist in the first iteration of your loop, it would be created depending on your assignment rvalue (xlsread output which seems to be n x 1 in the first iteration). In the second iteration you seem to assign a Matrix to the A(i,:) Vector which is not allowed (does not seem rational to put a Matrix into a Vector). Now you say that you have matrices with different dimensions in your xls files. If you are insisting on appending all of them into a matrix, you must first decide what you want to do with the empty indexes. Say you want to append a 3x3 matrix to a 2x2! You can turn the 2x2 into 3x2 and the append it to the 3x3 to have a 3x5 matrix. This way you will have two zero values in 3x2 matrix.

Mohammad
  • 464
  • 1
  • 3
  • 17