compare a vector with every cells element and get the missing

hi . i have a vector V=[1:100] and a C=cell(1-n) with double[] values . how could i get the values in the vector that are not in any element of cell ? and another question : how could i get a vector with repeats of elements in cell ? for example if there are three 2 in the all elements of cell , in my vector index(2) i have 2 ? thanks a lot !.

2 件のコメント

Adam
Adam 2017 年 8 月 7 日
編集済み: Adam 2017 年 8 月 7 日
Convert C to numeric and use
doc ismember
The second question is basically just a histogram isn't it?
doc histogram
Hamid Salari
Hamid Salari 2017 年 8 月 7 日
@Adam i will look into it . thanks .

サインインしてコメントする。

 採用された回答

Star Strider
Star Strider 2017 年 8 月 7 日

1 投票

Use setdiff inside cellfun:
V = 1:100;
C = {randi(100, 1, 75)}; % Create ‘C’
Out = cellfun(@setdiff, {V}, C, 'Uni',0); % Use ‘setdiff’
Result = [Out{:}] % Dsiplay Result (Not Necessary For The Code)

4 件のコメント

Hamid Salari
Hamid Salari 2017 年 8 月 7 日
編集済み: Hamid Salari 2017 年 8 月 7 日
@Star Strider . it works on a cell 1*1 . but my cell is 1*n and i need to check all the elements of cell .
Error using cellfun All of the input arguments must be of the same size and shape. Previous inputs had size 1 in dimension 2. Input #3 has size 12
Star Strider
Star Strider 2017 年 8 月 7 日
It is necessary to use a loop to get separate outputs from each comparison of the elements of ‘C’. (Using repmat with ‘{V}’ fails to do this.)
This should work:
V = 1:100;
C = {randi(100, 1, 75), randi(100, 1, 55)}; % Create ‘C’
for k1 = 1:size(C,2)
Out{k1} = cellfun(@setdiff, {V}, C(k1), 'Uni',0); % Use ‘setdiff’
end
Result = [Out{:}]; % Dsiplay Result (Not Necessary For The Code)
I do not know what size ‘C’ is, so I am assuming it is (1 x n). If it is (n x 1), change the size dimension to ‘size(C,1)’. (You could also use the length function, but without knowing more about ‘C’, I hesitate to suggest it.)
Hamid Salari
Hamid Salari 2017 年 8 月 7 日
@Star Strider. i got the idea behind it . thanks . my current cell is 1*12.
Star Strider
Star Strider 2017 年 8 月 7 日
My pleasure.
My code should work with it as written.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeTime Series Events についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by