FFT from a excel file
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I want to compute FFT on a set of data I have recorded.
Here is the code I am using and the error I am getting:
>> xdft = fft(channel1Data2(:,2));
Error using fft
Invalid data type. First argument must be double,
single, int8, uint8, int16, uint16, int32, uint32,
or logical.
2 comentarios
Respuestas (2)
MarKf
el 1 de Jun. de 2023
Well, make sure that the data contained in channel1Data2 is numeric (double, single, int8, etc..).
From the question title it seems that it is obtained by reading an Excel file, so likely the format/type has been messed up there. You could change the format to double with for example str2double (if the obtained data type happens to be a string), do check what's in that variable though (famous Excel® issue of converting values to nonsensical dates).
Star Strider
el 1 de Jun. de 2023
Editada: Star Strider
el 1 de Jun. de 2023
EDIT — (1 Jun 2023 at 16:07)
The array is table apparently created by readtable. Use cell array indexing (explained below) or refer to it as:
xdft = fft(channel1Data2.Ampl);
or:
xdft = fft(channel1Data2.{:,2});
The cell array indexing approaches will also work, so I will leave that part of my original Answer unchanged.
—
It could be that ‘channel1Data2’ is a cell array. If so, converting it to a numeric array should work —
channel1Data2 = num2cell(rand(10,2))
xdft = fft(cell2mat(channel1Data2(:,2))); % Use 'cell2mat'
xdft
xdft = fft([channel1Data2{:,2}]).'; % Cell Array Addressing (With Subsequent Transpose)
xdft
xdft = fft(vertcat(channel1Data2{:,2})); % Cell Array Addressing (With 'vertcat')
xdft
xdft = fft(channel1Data2(:,2)); % Numeric Array Addressing Of 'cell' Array (Reproduces The Error)
xdft
So there are several ways to solve this. Choose one.
.
0 comentarios
Ver también
Categorías
Más información sobre Data Type Conversion en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!