Operator '>' is not supported for operands of type 'struct'

15 次查看(过去 30 天)
i have two struct xin_s and yin_s and i need a1 and a2. i wrote:
lonsorgente = 14.2;
latsorgente = 40.8;
a1= xin_s > lonsorgente-0.5 & xin_s < lonsorgente+0.5;
a2= yin_s < latsorgente+0.5 & yin_s > latsorgente-0.5;
Error:
Operator '>' is not supported for operands of type 'struct'.
Error in prova_intdir_sorg (line 42)
a1= xin_s > lonsorgente-0.5 & xin_s < lonsorgente+0.5;
how can i select a range of values within a structure and get a1 and a2?
thanksss
  1 个评论
Stephen23
Stephen23 2022-7-10
"how can i select a range of values within a structure and get a1 and a2?"
Structures do not have any values.
However they do have fields, and fields can contain values. So you need to access the relevant fields of that structure:

请先登录,再进行评论。

采纳的回答

Image Analyst
Image Analyst 2022-7-10
What are the fields of xin_s? Let's say it's lat and lon. So you can compare the fields of xin_s rather than the whole structure itself:
lonsorgente = 14.2;
latsorgente = 40.8;
a1 = (xin_s.lon > lonsorgente-0.5) && (xin_s.lon < lonsorgente+0.5);
a2 = (yin_s.lat < latsorgente+0.5) && (yin_s.lat > latsorgente-0.5);

更多回答(1 个)

Dhritishman
Dhritishman 2022-7-10
a1= xin_s > lonsorgente-0.5 & xin_s < lonsorgente+0.5;
In the above code, xins_s is a structure. A structure has fields and those fields contain values. So, you need to compare the values of the fields of their structure, not the entire structure.
Let's say the structure xin_s has a field myField. You can now use the value of the myField field for comparison as done in your code. Access the field value by using a dot('.') in the following way:
a1= (xin_s.myField > lonsorgente-0.5) & (xin_s.myField < lonsorgente+0.5);

类别

Help CenterFile Exchange 中查找有关 Structures 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by