How to aplly a function to all columns?

3 ビュー (過去 30 日間)
Gabriel Aguirre
Gabriel Aguirre 2023 年 1 月 22 日
回答済み: dpb 2023 年 1 月 22 日
Hi guys, i have a code which do fft, however are so many columns to apply this code i need a way to do it faster, i already see something about cellfun, but this did't work. my data comes from vibration, I have a column of time and the rest of vibration data.
the following function makes the fft, psd now i want to apply to all columns of an excel table (csv).
function [freq_ax,fft_ax, psd_ax] = my_fft(t,ax)
%% computando fft
dt = mean(diff(t));
n = length(t);
L = 1:floor(n/2);
freq = 1/(dt*n)*(0:n-1);
fhat = (fft(ax,n)*1/(n-1));
fft_ax = abs(fhat(L));
freq_ax = (freq(L));
psd = fhat.*conj(fhat);
psd_ax = psd(L);
end

回答 (1 件)

dpb
dpb 2023 年 1 月 22 日
See fft -- in particular, note the first comment...
"fft(X) is the discrete Fourier transform (DFT) of vector X. For matrices, the fft operation is applied to each column."
Hence, you get the operations applied to all columns for free; just pass the vibration data array (without augmenting it with the time which is of no import for the FFT, all you need is the sample rate) to FFT and operate by column for the rest. You'll get N PSDs; one per column.

カテゴリ

Help Center および File ExchangeFourier Analysis and Filtering についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by