I am trying to run fft function for every row of 15x2045 matrix. 13 out of 15 rows have NaN as the last element (2045th element) How I can do it? so far I have tried this:
for k = 1:length(Final) %Final is 15x2045 matrix (I have converted a cell to this matrix)
HH = fft(Final{k},NFFT)/L;
power=(2*abs(HH(1:NFFT/2+1)));
end
%error I get is:Cell contents reference from a non-cell array object.
I appreciate any help, Thanks!

 採用された回答

Walter Roberson
Walter Roberson 2016 年 2 月 17 日
編集済み: Walter Roberson 2016 年 2 月 17 日

0 投票

for k = 1 : size(Final,1) %Final is 15x2045 matrix (I have converted a cell to this matrix)
HH(k,:) = fft(Final(k,:),NFFT)/L;
Fpower(k,:) = (2*abs(HH(k,1:NFFT/2+1)));
end
I renamed power to Fpower to avoid interfering with the MATLAB function named power (which is more commonly known as the .^ operator)
Note: you do not need to do this column by column. You can vectorize it as
HH = fft(Final, NFFT, 2)./L;
Fpower = 2 * abs(HH(:,1:NFFT/2+1));

7 件のコメント

Sag
Sag 2016 年 2 月 17 日
I get error: Assignment has more non-singleton rhs dimensions than non-singleton subscripts
Walter Roberson
Walter Roberson 2016 年 2 月 17 日
I have corrected the vectorized version. The other version was fine the way it was. Unless your L was a vector -- that would cause problems.
Remember to clear out your old HH before running the revised code.
clear HH
Sag
Sag 2016 年 2 月 17 日
編集済み: Walter Roberson 2016 年 2 月 17 日
Using
HH = fft(Final, NFFT, 2)./L;
Fpower = 2 * abs(HH(:,1:NFFT/2+1));
gave me
1) complex single HH (15x4096) with most of the elements are NaN + NaNi.
2) and a single Fpower (15x2049) with data in row 12 and 13 but NaN else everywhere.
Using for loop I keep getting the same error:
Assignment has more non-singleton rhs dimensions than non-singleton subscripts
Walter Roberson
Walter Roberson 2016 年 2 月 18 日
NFFT = 2^randi(20); Final = rand(15,2045); L = rand;
HH = fft(Final, NFFT, 2)./L;
sum(isnan(HH(:)))
ans =
0
Is your L possibly 0? Does your Final matrix have any nan in it? Does your Final matrix have any infinities in it? What is sum(isnan(Final(:))) and sum(isinf(Final(:)))
Sag
Sag 2016 年 2 月 18 日
yes there are 13 NaN in Final
Walter Roberson
Walter Roberson 2016 年 2 月 18 日
You need to expect NaN as the result for any row of Final that has a NaN in it. NaN "pollutes" or "taints" any calculation that it takes part in. Think of NaN as meaning "Any calculation involving this value is an error!". FFT has to determine contributions at various frequencies and with a data value that is error, it is not possible to determine the contributions.
If you are using NaN as a place-holder indicating that the data is missing or unknown and that the calculation should try to proceed without that data point, then FFT is the wrong calculation routine to use. You need to use a non-uniform FFT for such a situation. See http://www.mathworks.com/matlabcentral/fileexchange/25135-nufft--nfft--usfft and http://www.mathworks.com/matlabcentral/answers/113873-non-uniform-fft-with-matlab
Sag
Sag 2016 年 2 月 18 日
Thanks!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeNumeric Types についてさらに検索

タグ

質問済み:

Sag
2016 年 2 月 16 日

コメント済み:

Sag
2016 年 2 月 18 日

Community Treasure Hunt

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

Start Hunting!

Translated by