How to import a specific column from a matrix that is looping through a directory?

5 views (last 30 days)
So I am trying to bring in a set of excel spreadsheets in a loop which I have successfully done so i have a directory, but now i want to read column 5 of each spreadsheet as it loops round so I finish with all 41 columns of data saved into a single matrix. This is my script so far:
gAfiles=dir('*'); %create directory
%%creating loop
for i=9:50
filename=gAfiles(i,1);
z_force=readmatrix(filename);

Answers (1)

Cris LaPierre
Cris LaPierre on 28 Dec 2020
Use indexing to tell MATLAB where to store the results. You can find an example in the for loop documentation.
When importing the data with readmatrix, specify the "Range" name vaue pair so it reads the 5th column. You can see syntax and examples under Name-Value pair arguents in the readmatrix documentation page.

Community Treasure Hunt

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

Start Hunting!