Read certain range of csv file

83 ビュー (過去 30 日間)
Bryan
Bryan 2012 年 8 月 2 日
コメント済み: Matlaber 2019 年 2 月 15 日
Hi,
I want to load a .csv file, but only the content between A252 to D5352.
I've looked at help csvread, and it says I can load files using spreadsheet notation, but the help file is quite vague on this and no example is given.
I've tried
file = csvread('file.csv',A252,D5352,range);
file = csvread('file.csv',0,0,'A252..D5352');
any many other permuatations, but I can't get it to function.
Anybody who has done this before and got it to work?
Thanks Bryan

採用された回答

Eric
Eric 2012 年 8 月 3 日
編集済み: Eric 2012 年 8 月 3 日
There are several ways to do this:
1. Using csvread:
data = csvread('file.csv',251,0,'A252..D5352');
2. Using dlmread (which is what csvread actually calls)
data = dlmread('file.csv', ',', 251, 0, 'A252..D5352');
3. Using xlsread (Excel reads CSV files easily):
data = xlsread('file.csv', 'A252:D5352');
The trick with csvread and dlmread is that the r and c inputs must be consistent with the range that is passed in as a string at the end. Remember that these parameters are zero-based, so that column A maps to 0 and row 252 maps to 251.
Regards,
Eric
  1 件のコメント
Matlaber
Matlaber 2019 年 2 月 15 日
This is very helpful. Thanks.

サインインしてコメントする。

その他の回答 (2 件)

John Petersen
John Petersen 2012 年 8 月 2 日
Try
file = csvread('file.csv', 251, 0, [251 0 5351 5351+n]);
where n is the number of columns you want to read

Bryan
Bryan 2012 年 8 月 3 日
編集済み: Bryan 2012 年 8 月 3 日
Thanks for your comment.
Yes, that would work. But has anybody had success getting the "spreadsheet notiation" to work, as mentioned on the help file for csvread?

カテゴリ

Help Center および File ExchangeSpreadsheets についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by