Why does my uivhat produce table completely full of NaNs?
1 view (last 30 days)
Show older comments
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');
Answers (1)
Hornett
on 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
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!