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
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?
回答(1 个)
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.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 HDF5 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!