Delete all data points from the structure

3 ビュー (過去 30 日間)
laila fdoul
laila fdoul 2021 年 3 月 31 日
回答済み: Reshma Nerella 2021 年 4 月 4 日
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)

回答 (1 件)

Reshma Nerella
Reshma Nerella 2021 年 4 月 4 日
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!

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by