Effacer les filtres
Effacer les filtres

How to filter a cell array from entries from another cell array

3 vues (au cours des 30 derniers jours)
GMabilleau
GMabilleau le 4 Mai 2023
Commenté : GMabilleau le 4 Mai 2023
Hello,
I have a cell array, called cell1, containing a list of string variables. I would like to remove all variables with the same name in a second cell array, called cell2, and generate a thrid cell array, called cell3, with data from cell2 that were not present in cell1.
For example, let say that cell1 and cell2 are:
cell1 = {'aaa';'bbb';'ccc';'ddd'};
cell2 = {'bbb';'eee';'fff';'aaa';'ccc'};
How to get:
cell3 = {'eee';'fff'}
Thank you in advance,
Guillaume

Réponse acceptée

Stephen23
Stephen23 le 4 Mai 2023
Modifié(e) : Stephen23 le 4 Mai 2023
cell1 = {'aaa';'bbb';'ccc';'ddd'};
cell2 = {'bbb';'eee';'fff';'aaa';'ccc'};
cell3 = setdiff(cell2,cell1)
cell3 = 2×1 cell array
{'eee'} {'fff'}
  1 commentaire
GMabilleau
GMabilleau le 4 Mai 2023
Super! exactly what I was looking for. Thanks Stephen23.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Matrices and Arrays dans Help Center et File Exchange

Tags

Produits


Version

R2022b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by