How to aplly a function to all columns?

3 次查看(过去 30 天)
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 CenterFile Exchange 中查找有关 Fourier Analysis and Filtering 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by