csvread giving error "Index in position 2 exceeds array bounds (must not exceed 1)."

4 ビュー (過去 30 日間)
Mason Munoz
Mason Munoz 2020 年 3 月 15 日
回答済み: Rashed Mohammed 2020 年 3 月 18 日
I have a file 'Exact.csv' that is a 3x600001 matrix. I can't attach the file because it's too big.
csvread won't let me run any of the following lines of code:
>> csvread('Exact.csv',1,0,[1,0,1,45])
>> csvread('Exact.csv',1,0,[1,0,1,600000])
>> csvread('Exact.csv',1,0,[1,0,1,2])
>> csvread('Exact.csv',2,0,[2,0,2,600000])
It just gives the same error.
  2 件のコメント
Walter Roberson
Walter Roberson 2020 年 3 月 16 日
readtable() instead?
Walter Roberson
Walter Roberson 2020 年 3 月 16 日
Or readmatrix() for R2019b or later

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

回答 (1 件)

Rashed Mohammed
Rashed Mohammed 2020 年 3 月 18 日
Hi Mason,
I understand that you are not able read specific range of data from the .csv file using csvread function. When the files have greater than or equal to 100000 columns, the csvread function reads the data as a single column matrix. Hence the function is giving error when you are specifying a column offset ‘C2’ more than 0.
As csvread is not recommended starting from R2019a, use readmatrix function as already suggested by Walter Roberson.
% Read data from the csv file
full_data = readmatrix('Exact.csv');
% Read specific range of data
data1 = full_data(2,1:46);
data2 = full_data(2,1:600001);
data3 = full_data(2,1:3);
data4 = full_data(3,1:600001);
Note: Notice the change in indices used in the above example. It is because csvread uses offset from 0 but matlab array indexing starts from 1.
Hope this helps!

カテゴリ

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