从结构中删除大于特定值的数据 [英] Remove data from struct bigger than a certain value
问题描述
我有一个结构,即<1x1 struct>
,并且我正在尝试根据值在结构中编辑字段.该字段称为GeoDist_Actual
,该结构称为GeoDist_str
.字段GeoDist_Actual是<262792x1 double>
,这是我试图使用的代码,以消除大于1.609344e + 05的值.
I have a struct, that's a <1x1 struct>
, and I'm trying to edit a field in the struct based on the values. The field is called GeoDist_Actual
and the struct is called GeoDist_str
. The field GeoDist_Actual is a <262792x1 double>
, and this is the code I was trying to use in order to get rid of the values that are greater than 1.609344e+05.
i =1;
for i=i:size(GeoDist_str.GeoDist_Actual)
if GeoDist_str.GeoDist_Actual(i,1 > 1.609344e+05
GeoDist_str.GeoDist_Acutal(i,1) = [];
end
end
我如何附加或更改此代码,以使其按我的目标运行?我考虑过将所有值都设置为0,但是为了获得GPS值,进行反向Vincenty(球面)计算,我将不得不从中倒退,我想完全摆脱掉不符合if条件的值.
How would I append or alter this code in order to make it function like I'm aiming? I considered setting all the values to 0, but I'm going to have to go backwards from this in order to get back GPS values, doing a reverse-Vincenty(spherical) calculation, and I'd like to just completely get rid of the values that don't comply with the if condition.
如果我完全可以缩小问题的范围,请告诉我,并感谢您的提前帮助!
If I can narrow down the question at all, let me know, and thank you for your help in advance!
我注意到,当我更改该部分时
I've noticed that when I changed out the section
GeoDist_str.GeoDist_Actual(i,1) = [];
对于
GeoDist_str.GeoDist_Actual(i,1) = 0;
它实际上并没有解决任何问题,相反,它没有访问结构"GeoDist_str"中的"GeoDist_Actual"字段,它只是创建了一个值为0的镜像字段.
It didn't actually solve anything, instead it didn't access the field "GeoDist_Actual" within the struct "GeoDist_str", it just created a mirror field with values of 0.
推荐答案
请考虑以下示例:
% a 10-by-1 vector
x = [1;2;3;4;5;6;7;8;9;10];
% remove entries where the value is less than five
x(x<5) = [];
这称为逻辑索引,无需循环.
This is called logical indexing, no need for loops.
这篇关于从结构中删除大于特定值的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!