Operator '>' is not supported for operands of type 'struct'
15 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
ELISABETTA BILLOTTA
el 10 de Jul. de 2022
Respondida: Dhritishman
el 10 de Jul. de 2022
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 comentario
Stephen23
el 10 de Jul. de 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:
Respuesta aceptada
Image Analyst
el 10 de Jul. de 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);
0 comentarios
Más respuestas (1)
Dhritishman
el 10 de Jul. de 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);
0 comentarios
Ver también
Categorías
Más información sobre Structures en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!