필터 지우기
필터 지우기

Index exceeds the number of array elements

조회 수: 1 (최근 30일)
Niels de Vries
Niels de Vries 2020년 3월 28일
댓글: Ameer Hamza 2020년 3월 28일
Hello all,
I know there are several similar questions, but i didn't find a answer for my problem.
I am trying to load data from a .csv file with the simple csvread function.
The csv.file (see attachment) should contain 222.490 values.
Pos_x = csvread('C:\Users\Niels\Google Drive\position.csv',11,1);
However, i am getting the following error: 'Index exceeds the number of array elements (0).'
Creating a matrix of size 300.000x1 in matlab itself is no problem so i am not sure what the problem is, any suggestions?
Thanks in advance!

채택된 답변

Ameer Hamza
Ameer Hamza 2020년 3월 28일
편집: Ameer Hamza 2020년 3월 28일
Just giving the extension of .csv to a file does not automatically make it a csv file. Your file contains several alphabetic characters before the numeric values start. The following code will read the data as a text file and parse it to extract numeric values
f = fopen('position.csv');
data = textscan(f, '%s', 'HeaderLines', 11);
fclose(f);
str = [data{1}{:}];
idx = strfind(str, ':'); % finding the location of the last colon
values = sscanf(str(idx(end)+1:end), ',%f');
  댓글 수: 2
Niels de Vries
Niels de Vries 2020년 3월 28일
Thanks, works perfectly!
Ameer Hamza
Ameer Hamza 2020년 3월 28일
Glad to be of help.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by