how to set a range for xlsread command

I write a function to read all CSV files in my folder at once and and save all of them in one table. But I have problem regarding the xlsread command (ensemble data store).
I write my command in this way cell = xlsread(filename, 'H24:S1000'); and this command will be applied for all my CSV files in my folder. However my CSV files have different rows (some of them have more rows than 1000 rows and some of them have less).
Now what I need is to write my command in the way that be able to write this range "from column H row 24 to column S to last row" how should I set this range in my xlsread command.
Thanks for your help

1 Comment

I solve my problem in this way. I set the range of the csv file with maximum rows in xlsread command. However I would be happy if somebody suggests me a command since sometimes it is hard to know which file has the maximum rows.

Sign in to comment.

Answers (1)

Fangjun Jiang
Fangjun Jiang on 24 Jul 2018
Edited: Fangjun Jiang on 24 Jul 2018
I would just read the whole sheet and then cut it in MATLAB
[~,~,RawData]=xlsread(filename);
UsefulData=RawData(8:19,24:end);
% 8 and 19 are corresponding to column H and S
char('A'+7)
char('A'+18)
use csvread()
UsefulData=csvread('filename.csv',23,7);
UserfulData(:,19:end)=[];

4 Comments

first of all my data are too big and it is time consuming. More important, your command is useful when you want to read one csv file. as I wrote before my function read all csv files in the folder regardless of their names. So for instance when I have 200 csv file all 200 files will be organize in one table. in this case your suggested command will be useless
Use csvread('filename.csv', R, C) where R and C are the starting row and column position (zero based), so in your case would be csvread('filename.csv',23,7) and then you can cut the columns after column S (see updated answer).
In either case, you will need a for-loop to read 200 files. All the temporary variables can be re-used so it won't take 200 times of the memory.
there is no need to use for loop since there is data-store in matlab called "ensemble data" which can read all files with csv or mat extension but you should define a read function. however I found my solution. Tanx
Guillaume
Guillaume on 25 Jul 2018
Edited: Guillaume on 25 Jul 2018
first of all my data are too big and it is time consuming
Using xlsread to read csv data is always going to be very time consuming. dlmread, csvread or the more modern readtable (the latter sounding exactly like what you need) will all be significantly faster than xlsread.
xlsread delegates the parsing of the file to excel. The first thing matlab has to do is start excel (invisibly in the background) which takes a while. It's a complete waste of time when matlab is perfectly capable of reading the files itself.

Sign in to comment.

Categories

Products

Release

R2018a

Asked:

on 24 Jul 2018

Edited:

on 25 Jul 2018

Community Treasure Hunt

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

Start Hunting!