What is wrong with my code?
14 ビュー (過去 30 日間)
古いコメントを表示
hammer_data16 = importdata('10_24_2022m002_a_hammer_16dat.txt');
hammer_time16 = hammer_data16(:,1);
hammer_out16 = hammer_data16(:,3);
hammer_in16 = hammer_data16(:,2);
It is telling me "Index in position 2 exceeds array bounds. Index must not exceed 1".
0 件のコメント
回答 (1 件)
Askic V
2022 年 11 月 11 日
Execute command:
[r,c] = size(hammer_data16)
To see actual dimensions of the matrix hammer_data16 and then you'll see where the problem is. In order to diagnose further, more data is needed such as '10_24_2022m002_a_hammer_16dat.txt' file and the data line where Matlab interpreter reports the error.
But you'll probably figure it out yourself when you look at r and c variables.
2 件のコメント
Askic V
2022 年 11 月 11 日
編集済み: Askic V
2022 年 11 月 11 日
I think you now see the problem. if c is 1 it means it has only one column (in fact since r is also 1, it is only a number).
In line
hammer_out16 = hammer_data16(:,3);
you're trying to read all elements in the third column hence index is exceeded, because there is no third column of the data.
Please attach your source data file that you read into hammer_out16, because nothing is wrong with your code, the data in the file is the most likely a problem, especially if only one numer is read from the data file.
参考
カテゴリ
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!