Que hacer cuando aparece un dato discreto NaN

4 次查看(过去 30 天)
Buenos dias
tengo ese codigo:
[za,Kea,Vea] = Prucom;
%[z_A,z_B,z_C,z_D,z_E,Ke] = JUDP_t;
z1(k) = za; %za;
Ke(k) = Kea ; %Kea;
Ve(k) = Vea;
vsx(k) = Ve(k)*nay*sin(Ke(k)*pi/180);
vsy(k) = Ve(k)*nay*cos(Ke(k)*pi/180);
datos discretos za, Kea y Vea son captutrados por la funcion Prucom de un UDP. Algunas veces en lugar de un valor aparece
NaN y las siguientes instrucciones interrumpen el algoritmo.
Que debo hacer para que se ignore el dato NaN y no se interrumpa proceso
  2 个评论
Walter Roberson
Walter Roberson 2025-2-5
Approximate translation:
Discrete data za, Kea and Vea are captured by the Prucom function of a UDP. Sometimes instead of a value, NaN appears and the following instructions interrupt the algorithm.What should I do so that the NaN data is ignored and the process is not interrupted?
Guillermo Soriano
thank you Walter. I wroteed in spanish because the dialog was in my language.
Your translation is perfect... exactly what I asked in spanish.
Some ideas came to jump the process and therefore will not be made any correction. It is a extended kalman filter algorithm. If you have a better idea, please let me know it

请先登录,再进行评论。

回答(1 个)

Walter Roberson
Walter Roberson 2025-2-5
编辑:Walter Roberson 2025-2-5
In the worst case, there might be nothing you can do.
But possibly what you could do is convert your for loop into a while loop along these lines:
k = 0;
nanrun = 0;
while k <= NUMBER_OF_SAMPLES_TO_READ
[za,Kea,Vea] = Prucom;
if isnan(za) || isnan(Kea) || isnan(Vea);
nanrun = nanrun + 1;
if nanrun > LIMIT_ON_NUMBER_OF_NAN; break; end
continue;
else
nanrun = 0;
end
k = k + 1;
z1(k) = za; %za;
Ke(k) = Kea ; %Kea;
Ve(k) = Vea;
vsx(k) = Ve(k)*nay*sin(Ke(k)*pi/180);
vsy(k) = Ve(k)*nay*cos(Ke(k)*pi/180);
end
This reads up to NUMBER_OF_SAMPLES_TO_READ readings.
This also contains protections in case of lots of nan in a row; if there are more than LIMIT_ON_NUMBER_OF_NAN in a row then it stops reading.
  1 个评论
Guillermo Soriano
Thank you so much Walter. The algorithm is much longer but I believe these instructions will work.

请先登录,再进行评论。

产品


版本

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by