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!