フィルターのクリア

Confusion with for loop

1 回表示 (過去 30 日間)
Mayank Lakhani
Mayank Lakhani 2015 年 8 月 3 日
コメント済み: Mayank Lakhani 2015 年 8 月 4 日
Below is my code in which i am considering data file fb2010. At the end I have a matrix "resd". Now I want to add another three file fb2020, fb2030, fb2040. The code should be the same but including other three data files. At the end i should have four matrix like "resd"(including resd). So how to apply for loop. I tried to apply but it 's not working. Thanks in advance.
load('fb2010'); % loading the data
x = fb2010(3:1:1502,:);
% y_filt = filter(b,a,x); % filtering the received signal
y_filt= filter(b,a,x,[],2);
%%%%%%% fourier transform
nfft = length(y_filt);
res = fft(y_filt,nfft,2)/nfft;
res2 = res(:,1:nfft/2+1); %%%%taking single sided spectrum
res3 = fft(res2,[],2);
for i = 3:1:1500 %%%%dividing each row by first row.
resd(i,:) = res3(i,:)./res3(1,:);
end

採用された回答

Matt J
Matt J 2015 年 8 月 3 日
編集済み: Matt J 2015 年 8 月 3 日
Files={'fb2010','fb2020', 'fb2030', 'fb2040'};
for k=1:length(Files);
S=load(Files{i});
x = S.(Files{i})(3:1502,:);
....
for i = 3:1500
resd(i,:,k) = res3(i,:)./res3(1,:);
end
end
  2 件のコメント
Matt J
Matt J 2015 年 8 月 3 日
編集済み: Matt J 2015 年 8 月 3 日
Better. Replace the inner loop
for i = 3:1500
resd(i,:,k) = res3(i,:)./res3(1,:);
end
with a bsxfun operation,
resd(3:1500,:,k ) = bsxfun(@rdivide,res3(3:1500,:),res3(1,:));
Mayank Lakhani
Mayank Lakhani 2015 年 8 月 4 日
Thanks Matt for the Answer.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by