How to deleter specific elements from a matrix without changing its shape
10 次查看(过去 30 天)
显示 更早的评论
I have this matrix and i want to delete every number greater than 0.81 in each column but without changing the overall structure or size of the matrix. The number of columns should be the same only the values in each column should be limited ![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/531614/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/531614/image.png)
3 个评论
Walter Roberson
2021-2-25
Do I understand correctly that you want to end up with 20 columns, but each column would be a different length since different number of values would be deleted from it?
If so there is no way to do that using numeric arrays. You would have to put the values into cell arrays.
回答(2 个)
David Hill
2021-2-25
Instead of deleting why not change them to nan?
yourMatrix(yourMatrix>0.81)=nan;
Walter Roberson
2021-2-25
%perhaps you meant
yourMatrix(any(yourMatrix>0.81,2),:) = [];
%but column 20 is obviously different and perhaps it should be left out
mask = any(yourMatrix(:,1:end-1)>0.81,2);
yourMatrix(mask,:) = [];
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrices and Arrays 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!