cover cell array into vector

5 vues (au cours des 30 derniers jours)
Ana-Maria Pistea
Ana-Maria Pistea le 18 Mai 2020
hi all, I have this cell array and I want to conver it into a vector. The problem is that cell2mat will remove the empty cells and I want to keep them as = ' '.
Then I need to build again the cell array from the resulted vectore.
Any help would be appreciated.
  1 commentaire
Fangjun Jiang
Fangjun Jiang le 18 Mai 2020
You can't store empty '' or [] in numerical array. The best you can do is to replace it with zero or nan

Connectez-vous pour commenter.

Réponse acceptée

Stephen23
Stephen23 le 18 Mai 2020
Modifié(e) : Stephen23 le 18 Mai 2020
Numeric arrays do not have empty elements: every element has one value.
But you can easily store the sizes and recreate the cell array:
>> C = {[0;0],[],[],[0,1,2,3;0,0,0,0]};
>> S = cellfun('size',C,2);
>> M = cell2mat(C);
Recreate (strictly speaking the empty matrices have different sizes compared to those in C):
>> D = mat2cell(M,2,S);
  1 commentaire
Ana-Maria Pistea
Ana-Maria Pistea le 18 Mai 2020
This works. Thx a lot!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Cell Arrays dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by