Index in position 2 is invalid. Array indices must be positive integers or logical values.
2 ビュー (過去 30 日間)
古いコメントを表示
In the third line of code,
csvname = strcat(cpath, "\", cname);
c = csvread(csvname, 1, 0);
raw_data(:,i) = c(1:(min(size(c,1),max_val)),2:size(c,2));
where cpath and cname are the file path and file name of the file, I am getting this error:
Index in position 2 is invalid. Array indices must be positive integers or logical values.
I checked the csv file in question, and it is a valid file (no non-numeric values that are being read). A sample of the file is attached.
2 件のコメント
Stephen23
2019 年 7 月 30 日
@Varun Lakshmanan: please show us the complete error message. This means all of the red text. The error message has information that helps understand the problem.
回答 (2 件)
Walter Roberson
2019 年 7 月 30 日
Somehow you have managed to assign a value to a variable named csvread and that is interfering with your calling csvread as a function.
Note: if you want to skip the one line header in the file, then you should use 1, 0 instead of 2, 0 . The value is not which row number to start at: it is how many rows to skip, so to start at row 2 then you want to skip 1 row.
You should probably be considering readtable()
Andy
2019 年 7 月 30 日
If the 3 lines of code are all you are running, where is i set when you attempt to reference it in line 3?
2 件のコメント
Walter Roberson
2019 年 7 月 30 日
By default i is a function that returns sqrt(-1) so you will never get an error about i or j being undefined.
参考
カテゴリ
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!