How to remove an specific array from matrix
3 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Risposte (2)
Roger Stafford
il 16 Apr 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 Commenti
Stephen23
il 16 Apr 2017
Modificato: Stephen23
il 16 Apr 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 Commenti
Vedere anche
Categorie
Scopri di più su Multidimensional Arrays in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!