Borrar filtros
Borrar filtros

How do I delete empty rows in a matrix?

4 visualizaciones (últimos 30 días)
Franchesca
Franchesca el 14 de Mayo de 2014
Comentada: Honglei Chen el 14 de Mayo de 2014
%% Combine the data %combined = [6050,54]% define size of combined
SWOA = zeros(100,5); CWOA = zeros(100,5); SWA = zeros(100,5); CWA = zeros(100,5);
for i = 8:length(mydata)%loop to group data together into jump types
if grouped(i,4) == 1 % if data = 1 put in squat without arms
SWOA(i,1) = grouped(i,1);
else if grouped(i,4) == 2 % if data = 2 put in counter without arms
CWOA(i,1) = grouped(i,1);
else if grouped(i,4) == 3 % if data = 3 put in squat with arms
SWA(i,1) = grouped(i,1);
else if grouped(i,4) == 4 % if data = 4 put in counter with arms
CWA(i,1) = grouped(i,1);
else if grouped(i,4)== 0
continue
end
end
end
end
end
end
emptyCells = cellfun('isempty', SWOA);
SWOA(all(emptyCells,2),:) = []
In the variable SWOA for example it looks like this:
I am trying to delete all rows that have 0's in so that I am left with only about 5 or 6 rows of data that can be processed, how would I do this?

Respuesta aceptada

Honglei Chen
Honglei Chen el 14 de Mayo de 2014
CWOA(all(CWOA==0,2),:)=[]
  2 comentarios
Franchesca
Franchesca el 14 de Mayo de 2014
does this replace these lines:
emptyCells = cellfun('isempty', SWOA);
SWOA(all(emptyCells,2),:) = []
Thank you
Honglei Chen
Honglei Chen el 14 de Mayo de 2014
These are slightly different. Your code works for cells, and it is indeed looking for empty cells. But empty cell is different than a matrix that has all zeros. My code for the latter.
Your code would work for things like
x = cell(2,3)
x(2,3) = {1}
It will remove the first row

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Data Type Conversion en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by