csvread giving error "Index in position 2 exceeds array bounds (must not exceed 1)."
2 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(1 个)
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!
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!