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.
how to set a range for xlsread command
15 次查看(过去 30 天)
显示 更早的评论
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 个)
Fangjun Jiang
2018-7-24
编辑:Fangjun Jiang
2018-7-24
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 个评论
Guillaume
2018-7-25
编辑:Guillaume
2018-7-25
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.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Export to MATLAB 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!