Why does my uivhat produce table completely full of NaNs?

3 次查看(过去 30 天)
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 个评论
Di
Di 2022-11-23
Hi Jan,
Thanks for your reply. I've isolated the issue to fft(uiv) where uiv is a table filled with numbers and some NaNs. When I run fft(uiv) I get the table full of NaNs... Attached is the uiv file if you want to take a look. Stuck on this for many days.
Jan
Jan 2022-11-23
编辑:Jan 2022-11-23
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.

请先登录,再进行评论。

回答(1 个)

Nihal
Nihal 2024-9-16,8:11
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

标签

产品


版本

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by