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

4 Ansichten (letzte 30 Tage)
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.

Antworten (1)

Rashed Mohammed
Rashed Mohammed am 18 Mär. 2020
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!

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by