Concatenating matrix with specific cell in cell aray

1 vue (au cours des 30 derniers jours)
Ori Shenyan
Ori Shenyan le 9 Mai 2022
Commenté : Dyuman Joshi le 9 Mai 2022
I have the following 53x2 cell array, organised as follows:
Each cell in the second column is as follows:
For each of these cells, I would like to check if a matrix of numbers is present: j = [2, 48, 17:33]. If the numbers in this matrix are not contained in this cell, I would like to add them.
I thought about something where I concatenate each cell element with the matrix in a loop and then remove duplicates but I am not sure the best way to go about it.
Thank you very much for any help in advance.
  1 commentaire
Dyuman Joshi
Dyuman Joshi le 9 Mai 2022
Yes, you can use a for loop to go through the cell.
for i=1:size(cellname,1)
%check if the required elements are present or not
if all(ismember([2 48 17:33], cellname{i,2}))
...
else
...
end
end

Connectez-vous pour commenter.

Réponses (1)

Stephen23
Stephen23 le 9 Mai 2022
C = {'hello',[1,2,5];'world',[3,5]}
C = 2×2 cell array
{'hello'} {[1 2 5]} {'world'} {[ 3 5]}
V = [4,5];
F = @(a)union(V,a);
C(:,2) = cellfun(F,C(:,2),'uni',0)
C = 2×2 cell array
{'hello'} {[1 2 4 5]} {'world'} {[ 3 4 5]}

Catégories

En savoir plus sur Matrix Indexing dans Help Center et File Exchange

Produits


Version

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by