- Technical Services and Consulting
- Embedded Systems | Firmware Developement | Simulations
- Electrical and Electronics Engineering
index exceeds array bounds
조회 수: 7 (최근 30일)
이전 댓글 표시
The object of my code is to traverse a matrix and remove each row that contains a zero in any of the columns. I keep getting this error: "Index in position 1 exceeds array bounds. Index must not exceed 253."
This is the code:
load('data')
[nRows, nCols] = size(data);
for row = 1:nRows
for col = 1:nCols
if data(row,col) == 0
data(row,:) = [];
[nRows, nCols] = size(data);
end
end
end
댓글 수: 0
답변 (1개)
Hassaan
2024년 3월 25일
load('data') % Assuming 'data' is your matrix
% Find rows with any zero element
rowsWithZero = any(data == 0, 2);
% Remove those rows
data(rowsWithZero, :) = [];
% If needed, you can now work with the modified 'data' matrix.
-----------------------------------------------------------------------------------------------------------------------------------------------------
If you find the solution helpful and it resolves your issue, it would be greatly appreciated if you could accept the answer. Also, leaving an upvote and a comment are also wonderful ways to provide feedback.
It's important to note that the advice and code are based on limited information and meant for educational purposes. Users should verify and adapt the code to their specific needs, ensuring compatibility and adherence to ethical standards.
Professional Interests
Feel free to contact me.
댓글 수: 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!