Matlab: How to convert matrix columns to a numeric cell array?

15 vues (au cours des 30 derniers jours)
Renu Kadolkar
Renu Kadolkar le 5 Mar 2020
I have a matrix of size (105201,3).
The structure looks something like:
10100 1119 32
10100 1121 49
10100 2361 120
10100 2362 143
10100 2373 142
I want to convert it to a cell array such that I can perform the following:
emptyIndex = cellfun('isempty',cellArray); %# Find indices of empty cells
cellArray(emptyIndex) = {0}; %# Fill empty cells with 0
employmentOut = cell2mat(cellArray); %# Convert the cell array
The output matrix should have the first 2 columns as categorical values and 3rd as corresponding values:
`1119 1121....
10100 32 49
....
  2 commentaires
Bob Thompson
Bob Thompson le 5 Mar 2020
How can you have a matrix of doubles with empty values? Are they NaN? It shouldn't be necessary to convert the array into a cell array to find the nan values.
No matter what, you can convert the array into cells will mat2cell.
Adam Danz
Adam Danz le 6 Mar 2020
To echo what Bob Nbob stated, matrices can have NaN values but not empty or missing values. To replace NaNs with 0s,
M(isnan(M)) = 0;

Connectez-vous pour commenter.

Réponses (1)

Srivardhan Gadila
Srivardhan Gadila le 13 Mar 2020
A matrix can't have an empty value. The whole array itself should be empty.
Therefore from the above mentioned code, the value of emptyIndex would be empty.
If you are having any NaN, inf then find them using isnan & isinf functions.
You can refer to:
  1. How to write the matrix with blank element?
  2. Assign empty value(s) to matrix elements (to delete those elements) fails
  3. empty
  4. Empty Arrays

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by