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

15 views (last 30 days)
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 Comment
Stephen23
Stephen23 on 10 Jul 2022
"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:

Sign in to comment.

Accepted Answer

Image Analyst
Image Analyst on 10 Jul 2022
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);

More Answers (1)

Dhritishman
Dhritishman on 10 Jul 2022
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);

Categories

Find more on Structures in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!