How to deleter specific elements from a matrix without changing its shape
Mostra commenti meno recenti
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 Commenti
Walter Roberson
il 25 Feb 2021
When you "delete" you end up with less than you had, so the result could not have the same size.
There are only 4 rows in which none of the values exceed the bounds, so in order to keep the same shape the output would have to be 4 x 20.
Maaz Madha
il 25 Feb 2021
Walter Roberson
il 25 Feb 2021
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.
Risposte (2)
David Hill
il 25 Feb 2021
Instead of deleting why not change them to nan?
yourMatrix(yourMatrix>0.81)=nan;
1 Commento
Maaz Madha
il 25 Feb 2021
Walter Roberson
il 25 Feb 2021
%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,:) = [];
Categorie
Scopri di più su Matrix Indexing in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!