Concatenating matrix with specific cell in cell aray
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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
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
Réponses (1)
Stephen23
le 9 Mai 2022
C = {'hello',[1,2,5];'world',[3,5]}
V = [4,5];
F = @(a)union(V,a);
C(:,2) = cellfun(F,C(:,2),'uni',0)
0 commentaires
Voir également
Catégories
En savoir plus sur Matrix Indexing 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!