Delete all data points from the structure

2 visualizzazioni (ultimi 30 giorni)
laila fdoul
laila fdoul il 31 Mar 2021
Risposto: Reshma Nerella il 4 Apr 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)

Risposte (1)

Reshma Nerella
Reshma Nerella il 4 Apr 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!

Categorie

Scopri di più su Structures in Help Center e File Exchange

Prodotti


Release

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by