Concatenating matrix with specific cell in cell aray
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
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 comentario
Dyuman Joshi
el 9 de Mayo de 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
Respuestas (1)
Stephen23
el 9 de Mayo de 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 comentarios
Ver también
Categorías
Más información sobre Matrix Indexing en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!