Extract specific rows and columns from excel and store in a matrix
Show older comments
Hi I have two questions
- I have multiple excel files that I want to use matlab to extract specific row and columns from and then save the new data in a matrix for plotting afterwards. So logically, I want matlab to go inside a folder to read excel filename number1, extracting rows(3:till end) and column (I:K), then store it in a matrix in matlab. Next, matlab goes back to the folder and reads excel filename number2, extracting rows(3:till end) and column (I:K), then store it in a matrix and so on and so forth. So it does that same procedure for all the excel files in the folder. The figure below shows how each of the excel files are formatted with data.
- After the data is extracted and those matrices are made, I want to plot all those three columns on one 2D figure (X axis is Time, Left Y-axis is PSI and Right Y-axis is ROLL). Given that my data is huge, I am worried it might not all plot on one figure. So if you could provide another option to plot for each matrix, please tell me
The files are very large so I can't unfortunately combine them into one. I have to extract each excel seperately but if I can first extract the data I need and then have some sort of loop or whatever works that plots the data of the all the matrices three columns on one figure.

Accepted Answer
More Answers (2)
David Hill
on 11 Aug 2022
If formating is consistent, readmatrix should work.
listing=dir;
M=[];
for k=1:length(listing)
m=readmatrix(listing(k).name);%I am assuming the header information will be removed and formatting is consistent
M=[M;m(:,9:11)];%assuming you can fit all your data together (not too big)
end
4 Comments
mpz
on 11 Aug 2022
David Hill
on 11 Aug 2022
Edited: David Hill
on 11 Aug 2022
for k=1:20
m=readtable(sprintf('Number%d.xlsm',k));
end
mpz
on 11 Aug 2022
David Hill
on 11 Aug 2022
Should be k!
M=[];
for k = 1 : 20
T =readtable(sprintf('Number%d.xlsm',k));%need to be inside the folder or update name
M=[M;T(1:end,9:11)];
end
mpz
on 12 Aug 2022
Categories
Find more on Spreadsheets in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!