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

조회 수: 15 (최근 30일)
ELISABETTA BILLOTTA
ELISABETTA BILLOTTA 2022년 7월 10일
답변: Dhritishman 2022년 7월 10일
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