cell array to logical
108 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/763831/image.png)
I have this cell array and i want to convert this to logical array.
Thank you
1 comentario
Respuestas (1)
DGM
el 11 de Oct. de 2021
Editada: DGM
el 11 de Oct. de 2021
In order to make a logical array of it, you'll have to specify the conditions where the output is true. Consider two examples:
A = {1; 1; 1; []; 1; 1; []; 0; 0.1}
% true if non-empty
B = ~cellfun(@isempty,A)
% true if nonzero
C = cellfun(@(x) x~=0,A,'uniform',false)
% true if non-empty and nonzero
D = cellfun(@(x) ~isempty(x) && x~=0,A)
Note that the second example is still a cell array. This is required if empty elements are to be preserved,.
2 comentarios
Jan
el 11 de Oct. de 2021
When the elements of the cell array are numerical arrays, this is faster:
B = ~cellfun('isempty', A)
Ver también
Categorías
Más información sobre Multidimensional Arrays 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!