How to delete elements from cell arrays?

14 visualizaciones (últimos 30 días)
Jung BC
Jung BC el 30 de Mzo. de 2016
Respondida: Walter Roberson el 31 de Mzo. de 2016
Hi, I have a cell array(1x316) which contains 316 double
numeric arrays of various sizes like 74845x1,81032x1,55434x1 and so on.
I want to delete data values from each array cells which is greater than 140 and save it in a new cell array.
Format of my data looks like below:-
inst_speed_all_user_rome.mat(cell array)->speed_kmh(variable)->
1 2 3 ... ....316(total 316 cells of arrays)
{74845x1 double},{81032x1 double},{87351x1 double},.....
sample of one array inside one of those 316 cells :
speed_kmh{1,1}-> {74845x1}= 44.889 28.445 0 156 33.46 ........
Now, for above scenario,i need to delete the data 156(which is greater than 140 here) likewise i want to delete all data values > 140 from all arrays.
Initially i have stored cell array in s1 which is a 1x1 struct with one field ->speed_kmh of size 1x316.
Please help me out on this.
This is my code but i am stuck.
%%store cell array in struct s1
s1 =load('inst_speed_usr_rome.mat');
%%delete the values greater than 140 from cells
l = s1.speed_kmh{:};
to_delete = false(size(l));
for i=1:length(s1.speed_kmh)
if (s1.speed_kmh(i)>140)
to_delete(i) = true;
end
end
l(to_delete) = [];
  2 comentarios
Image Analyst
Image Analyst el 30 de Mzo. de 2016
So you have a cell array with 316 cells. And inside each of those 316 cells is another cell array? Or is a regular numerical array inside the cells? Please read the FAQ http://matlab.wikia.com/wiki/FAQ#What_is_a_cell_array.3F before you answer.
Jung BC
Jung BC el 30 de Mzo. de 2016
Hi,It's a cell array of 316 cells.And each of those cells are double numeric arrays of diferent sizes.

Iniciar sesión para comentar.

Respuesta aceptada

Jan
Jan el 31 de Mzo. de 2016
Perhaps:
s1 = load('inst_speed_usr_rome.mat');
for k = 1:numel(s1.speed_kmh)
v = s1.speed_kmh{k};
s1.speed_kmh{k} = v(v <= 140);
end

Más respuestas (2)

MHN
MHN el 30 de Mzo. de 2016
l(to_delete,:) = [];
  3 comentarios
MHN
MHN el 30 de Mzo. de 2016
If it is possible, attach inst_speed_usr_rome.mat
Jung BC
Jung BC el 31 de Mzo. de 2016
Sorry, the file is very large in size to attach here.I have edited my question above.Hope you can analyse it more clearly.

Iniciar sesión para comentar.


Walter Roberson
Walter Roberson el 31 de Mzo. de 2016
cellfun(@(C) struct('speed_kmh', C.speed_kmh(C.speed_kmh<=140)), s1, 'Uniform', 0)

Categorías

Más información sobre Structures en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by