I have 100x73 double mat file as shown in image. I want to remove all zero values from this file and save it to a new mat file. How can I do it? Thank you.
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
sam
el 21 de Sept. de 2022
Comentada: Akira Agata
el 22 de Sept. de 2022
9 comentarios
Akira Agata
el 22 de Sept. de 2022
Editada: Akira Agata
el 22 de Sept. de 2022
Is it OK to separate each row with different length?
Like:
A = [1 0 2;...
2 3 4]
To
C = {[1 2];...
[2 3 4]}
Respuesta aceptada
Walter Roberson
el 22 de Sept. de 2022
It is not possible to have a numeric matrix that contains blanks.
It is not possible to have a numeric matrix that contains a different number of entries in a row or column.
It is possible to write functions that display blanks in place of zeros. For example,
A = rand(5,7); A(randi(35, 1, 4)) = 0
C = compose('%6.4f', A)
C(A == 0) = {' '};
D = arrayfun(@(R) strjoin(C(R,:), ' '), (1:size(C,1)).', 'uniform', 0);
D = vertcat(D{:});
disp(D)
1 comentario
Akira Agata
el 22 de Sept. de 2022
+1
Another possible solution:
% Sample matrix
A = randi(10, 5, 7);
A(randi(35, 1, 8)) = 0
% Replace 0 with NaN and apply rmmissing for each row
A(A==0) = nan;
C = mat2cell(A, ones(size(A, 1), 1));
C = cellfun(@rmmissing, C, "UniformOutput", false)
Más respuestas (0)
Ver también
Categorías
Más información sobre Environment and Settings 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!