How to deleter specific elements from a matrix without changing its shape

조회 수: 12 (최근 30일)
Maaz Madha
Maaz Madha 2021년 2월 25일
답변: Walter Roberson 2021년 2월 25일
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
  댓글 수: 3
Maaz Madha
Maaz Madha 2021년 2월 25일
i meant the same number of columns. So deleting any value greater than 0.81 in each column( for example deleting 1.0071 onwards from the first column) and so on and so forth for each column
Walter Roberson
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
David Hill 2021년 2월 25일
Instead of deleting why not change them to nan?
yourMatrix(yourMatrix>0.81)=nan;
  댓글 수: 1
Maaz Madha
Maaz Madha 2021년 2월 25일
becasue i want to use these values for further calculations and im not sure nan would work with calculations

댓글을 달려면 로그인하십시오.


Walter Roberson
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,:) = [];

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by