Que hacer cuando aparece un dato discreto NaN
3 views (last 30 days)
Show older comments
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
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?
Answers (1)
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.
See Also
Categories
Find more on HDF5 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!