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 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