Create new variable from an existing variable but deleting some outliers
1 次查看(过去 30 天)
显示 更早的评论
Hello!
I'm working with a NetCDF file and I have values of T,S,density,depth, chlorophyll and oxygen measured in time.
I plotted a vertical profile of oxygen with depth and I saw there were some outliers that need to be removed. So, I would like to create a new variable (oxycor) from the original oxygen variable but without those values. I would like to remove those values right in the corner with concentration of oxygen equal to zero.
I tried this and then plotting with 'glider.oxycor' but it says vectors must be the same length.
oxycorrection2=find(glider.oxy>150);
glider.oxycor=glider.oxy(oxycorrection2);
What am I doing wrong?
Thank you!!
2 个评论
Walter Roberson
2022-3-5
Is glider a struct() or is it a table()
If it is a table, then you are trying to have the glider.oxy column be full length but the glider.oxycor column be shorter.
采纳的回答
Walter Roberson
2022-3-5
mask = glider.oxy>150;
glider_subset = glider(mask,:);
更多回答(1 个)
Steven Lord
2022-3-5
Remove all rows in the table that have an outlier value for the oxy variable. Here's a similar example using the sample patients data.
load patients
P = table(LastName, Age, Height, Weight);
P2 = P; % Make a backup copy before outlier removal
fprintf("P has %d rows before outlier removal\n", height(P))
head(P)
Let's say outliers are patients that are younger than 40.
tooYoung = P.Age < 40;
P(tooYoung, :) = [];
fprintf("P has %d rows after outlier removal\n", height(P))
head(P)
Note that several patients younger than 40 appeared in the table before outliers were removed, but afterwards the first patient in the resulting table was Johnson at 43 years old.
Now if you wanted to keep the data but not plot it, you could do that either by just using logical indexing or, if you want to compute with it more often, adding that as a new variable to the table.
P2.tooYoung = tooYoung;
head(P2)
plot(P2{tooYoung, "Height"}, P2{tooYoung, "Weight"}, 'o'); % or
figure
scatter(P2{P2.tooYoung, "Height"}, P2{P2.tooYoung, "Weight"})
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Weather and Atmospheric Science 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!