Extracting specific numbers from a vector

6 vues (au cours des 30 derniers jours)
Darren Robinson
Darren Robinson le 19 Août 2016
Modifié(e) : Azzi Abdelmalek le 19 Août 2016
How can I extract a specific number from a vector, saving the new vector minus the extracted number as a new variable, and saving the counted extracted number as a new variable?
eg. Extracting '-20' from the following.
A = [2 4 6 5 6 5 4 3 -20 4 6 7 -20 3 4 5 6 1 -20];
A1 = [2 4 6 5 6 5 4 3 4 6 7 3 4 5 6 1];
A2 = 3

Réponses (2)

Walter Roberson
Walter Roberson le 19 Août 2016
A1 = A(A ~= -20);
A2 = length(A) - length(A1);

Azzi Abdelmalek
Azzi Abdelmalek le 19 Août 2016
Modifié(e) : Azzi Abdelmalek le 19 Août 2016
idx=ismember(A,-20)
A1=A(~idx)
A2=sum(idx)

Catégories

En savoir plus sur Networks 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