Borrar filtros
Borrar filtros

How to insert the missing number into the cell array?

1 visualización (últimos 30 días)
Hang Vu
Hang Vu el 14 de Mayo de 2019
Editada: Hang Vu el 14 de Mayo de 2019
Suppose that I have this
I=[3 5 6 8 10 11]
A={[3];[6;8];[];[11]}
How to find the missing number of I in A and insert that number into any position of A? for intance like:
A={[3];[6;8];[5];[10;11]}
  4 comentarios
Akira Agata
Akira Agata el 14 de Mayo de 2019
Editada: Akira Agata el 14 de Mayo de 2019
One quick question:
How did you define the position of '10' in your cell array A?
Hang Vu
Hang Vu el 14 de Mayo de 2019
It will be random sir. That is just my example, I want to randomly insert the missing numbers into A, not only the empty cell

Iniciar sesión para comentar.

Respuesta aceptada

KSSV
KSSV el 14 de Mayo de 2019
I=[3 5 6 8 10 11] ;
A={[3];[6;8];[];[11]} ;
% get empty cell
idx = cellfun(@isempty,A) ;
A{idx} = setdiff(I,cell2mat(A))
  11 comentarios
KSSV
KSSV el 14 de Mayo de 2019
I=[3 5 6 8 10 11] ;
A={[3];[6;8];[];[11]} ;
% get empty cell
idx = cellfun(@isempty,A) ;
missing = setdiff(I,cell2mat(A)) ;
A{idx} = missing(1)
Hang Vu
Hang Vu el 14 de Mayo de 2019
Editada: Hang Vu el 14 de Mayo de 2019
Thank you so much! I modified a bit and it worked.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Creating and Concatenating Matrices 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!

Translated by