How to remove an specific array from matrix
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Matrix A as follows:
A = [
1 2 0 0 0
2 100 5 100 1
36 12 25 100 0
8 5 100 0 0
9 1 2 5 9
1 2 3 89 100
];
I want to remove any array which is equal to 100 from matrix A and form matrix L:
L = [
1 2 0 0 0
2 5 1 0 0
36 12 25 0 0
8 5 0 0 0
9 1 2 5 9
1 2 3 89 0
];
0 commentaires
Réponses (2)
Roger Stafford
le 16 Avr 2017
[m,n] = size(A);
for k = 1:m
a = A(k,A(k,:)~=100);
A(k,:) = [a,zeros(1,n-length(a))];
end
0 commentaires
Stephen23
le 16 Avr 2017
Modifié(e) : Stephen23
le 16 Avr 2017
>> A = [1,2,0,0,0;2,100,5,100,1;36,12,25,100,0;8,5,100,0,0;9,1,2,5,9;1,2,3,89,100];
>> L = A;
>> L(L==100) = 0;
>> L = cell2mat(cellfun(@(v)[v(v~=0),v(v==0)],num2cell(L,2),'uni',0))
L =
1 2 0 0 0
2 5 1 0 0
36 12 25 0 0
8 5 0 0 0
9 1 2 5 9
1 2 3 89 0
0 commentaires
Voir également
Catégories
En savoir plus sur Multidimensional Arrays dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!