Effacer les filtres
Effacer les filtres

combining lots of vectors of unequal length

1 vue (au cours des 30 derniers jours)
Haneya Qureshi
Haneya Qureshi le 3 Avr 2018
Commenté : Stephen23 le 3 Avr 2018
i have: a=[1 2 3 0 0] b=[4 5 6 7 0 0 0] c=[8 9] i want: d= [a b c] with zeros removed d=[1 2 3 4 5 6 7 8 9]
Is there a generic code for this? because i have lots of vectors like a,b and c and their length is very large and unequal

Réponses (1)

Akira Agata
Akira Agata le 3 Avr 2018
I don't think there is a generic code. How about making a function to do this, like:
function [d1,d2] = yourFunction(a,b,c)
d1 = [a,b,c];
idx = d1 == 0;
d2 = d1(~idx);
end
Here is an example.
>> [d1,d2] = yourFunction([1 2 3 0 0],[4 5 6 7 0 0 0],[8 9])
d1 =
1 2 3 0 0 4 5 6 7 0 0 0 8 9
d2 =
1 2 3 4 5 6 7 8 9

Catégories

En savoir plus sur Matrices and 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!

Translated by