Why does my uivhat produce table completely full of NaNs?
Afficher commentaires plus anciens
Just started with MATLAB, so absolutely no clue what I'm doing. Any help will be appreciated. I think the main issue stems from uivhat giving NaNs in the resulting table after transforming back into real.
%Express currents in terms of complex velocity
uiv = kadcp.Evel + 1i*kadcp.Nvel;
H = find(sum(isfinite(uiv),2)>10000 & sum(isfinite(uiv))<size(uiv,2));
for n=1:length(H)
A = find(isfinite(uiv(:,H(n))));
B = find(isnan(uiv(:,H(n))));
uiv(B,H(n)) = interp1(A, uiv(A, H(n)),B); % interpolate across missing data depth by depth
end
%Define sample frequency
tlength = 17824;
samplefreq = 2;
deltafreq = samplefreq/tlength;
freq = deltafreq :deltafreq :samplefreq/2;
%Compute Fourier coefficient
uivhat = real(fft(uiv).*conj(fft(uiv)));
%Retrieve spectra coefficient for neative and positive frequencies
CW = uivhat(2:(length(freq))+1,:); % clockwise components
CCW = flipud(uivhat([2+length(freq):end, 1],:));% counterclockwise components
%Band-average to reduce noise
CW = runmean(CW, 2);
CCW = runmean(CCW, 2);
%Plotting the spectra for CW and CCW
figure(4);
loglog(freq,CW,'r',freq,CCW,'b');

3 commentaires
Jan
le 23 Nov 2022
Without having your input arguments, we cannot run the code and cannot check, where the NaN values are coming from.
You can step through the code line by line using the debugger: Set a breakpoint in the left bar of the editor. Now check line by line, which calculations produce the NaNs.
Di
le 23 Nov 2022
I do not see any table objects here. Do you mean "vector"?
Did you check, where the first NaN occurs?
dbstop if naninf
I boldly guess it is interp1 outside the defined range.
Réponses (1)
Hornett
le 16 Sep 2024
Hi,
I understand that you have a dataset called "uiv". However, when you apply the "fft" function to it, the resulting matrix is entirely composed of NaN values.
The “fft” function will return all values as NaN even if a single value among them is NaN, so you will have to remove all the NaN values from your dataset.
Here is the example code which you can use to remove NaNs.
matrix = uiv;
matrixWithoutNaNs = matrix;
matrixWithoutNaNs(isnan(matrixWithoutNaNs)) = 0;
% Display the matrix without NaNs
disp(matrixWithoutNaNs);
You can also use “fillmissing” function to fill any NaN value with constant.
Refer to the documentation link of “fft” and “fillmissing” functions
Catégories
En savoir plus sur NaNs dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!