Que hacer cuando aparece un dato discreto NaN

3 views (last 30 days)
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 Comments
Walter Roberson
Walter Roberson on 5 Feb 2025
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
Guillermo Soriano on 5 Feb 2025
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

Sign in to comment.

Answers (1)

Walter Roberson
Walter Roberson on 5 Feb 2025
Edited: Walter Roberson on 5 Feb 2025
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 Comment
Guillermo Soriano
Guillermo Soriano on 6 Feb 2025
Thank you so much Walter. The algorithm is much longer but I believe these instructions will work.

Sign in to comment.

Products


Release

R2019a

Community Treasure Hunt

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

Start Hunting!