Delete all data points from the structure

7 vues (au cours des 30 derniers jours)
laila fdoul
laila fdoul le 31 Mar 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)

Réponses (1)

Reshma Nerella
Reshma Nerella le 4 Avr 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!

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Produits


Version

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by