I got data with a lot of zeros. Now i want to empty every cell with a zeros, but i don't want to remove the cell from my data set. I got this: The data set is 20535x1536

9 visualizaciones (últimos 30 días)
>> for i = 1:20535;
j= 1:1536;
if y(j,i)~= 0;
x(j,i)=y(j,i);
else y(j,i) == 0 ;
x(j,i)= {};
end;
end;
Conversion to double from cell is not possible.

Respuestas (1)

Guillaume
Guillaume el 19 de Sept. de 2018
A matrix cannot have empty cells. They must have a value. My suggestion is to use NaN (not a number) to mark those cells you consider invalid. This is trivially done:
x = y;
x(x == 0) = NaN;
and I would strongly recommend you do that. You can test for cells that are NaN with isnan
A cell array can have empty cells. You could indeed convert your matrix into a cell array and empty the cells that contai a scalar 0. This is what your clumsy code attempts to do. I would strongly recommend against that. A cell array is not a matrix, you cannot perform any kind of arithmetic on a cell array, and you can't pass it to functions that expect a matrix. Cell arrays are harder to work with that matrices and also use about 15 times more memory. A 203535x1536 cell array will requires ~3.5 GB, a matrix the same size only ~240 MB.
If you are really hell bent on using a cell array:
x = num2cell(y);
x(y == 0) = {};

Categorías

Más información sobre Matrix Indexing 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