Concatenating matrix with specific cell in cell aray

1 view (last 30 days)
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 Comment
Dyuman Joshi
Dyuman Joshi on 9 May 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

Sign in to comment.

Answers (1)

Stephen23
Stephen23 on 9 May 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]}

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!