Delete all data points from the structure

2 visualizaciones (últimos 30 días)
laila fdoul
laila fdoul el 31 de Mzo. de 2021
Respondida: Reshma Nerella el 4 de Abr. de 2021
i would like to delete all data points from the time series for which the following condition is true :
(temp < 2) & (speed < 1)
my_structure = 1 * 3 struct
the structure contains 4 fields : date, temp, speed and power
i used the following code but it didn't work:
temp_data = [my_structure.temp]
speed_data = [my_structure.speed]
for i = 1:size(my_structure, 2)
j = 1:length(temp_data)
to_remove = or((temp_data(j,i) < 2 ) , (speed_data(j,i) < 1))
if to_remove(j) == 1
to_remove(j) = []
end
end
display(my_structure)

Respuestas (1)

Reshma Nerella
Reshma Nerella el 4 de Abr. de 2021
Hi,
From my understanding, you want to certain datapoints in the structure satisfying either of the two conditions i.e (temp < 2) & (speed < 1).
To acheive this, you can modify your code as follows:
for i = 1:size(my_structure,2)
if(my_structure(i).temp < 2) % check if the temp value is 2 is that particular row of struct
my_structure(i).temp = []; % if yes, set it to [].
end
if(my_structure(i).speed < 1)
my_structure(i).speed = [];
end
end
Hope this helps!

Categorías

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

Productos


Versión

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by