FFT from a excel file
4 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(2 个)
MarKf
2023-6-1
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
2023-6-1
编辑:Star Strider
2023-6-1
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Type Conversion 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!