Error using * MTIMES is not fully supported for integer classes. At least one input must be scalar.
조회 수: 33 (최근 30일)
이전 댓글 표시
I'm trying to implement a 1 dimensional DFT without using Matlab built-in functions such as fft(). This is my code:
function [Xk] = dft1(xn)
N=length(xn);
n = 0:1:N-1; % row vector for n
k = 0:1:N-1; % row vecor for k
WN = exp(-1j*2*pi/N); % Twiddle factor (w)
nk = n'*k; % creates a N by N matrix of nk values
WNnk = WN .^ nk; % DFT matrix
Xk = (WNnk*xn );
when i run the code after using the following commands:
I = imread('sample.jpg')
R = dft1(I)
I get this particular error: *Error using * MTIMES is not fully supported for integer classes. At least one input must be scalar. To compute elementwise TIMES, use TIMES (.*) instead.*
Can someone please help me to figure out how to solve this problem
Note: I am still in the very beginning level of learning Matlab. Thank you very much
댓글 수: 0
채택된 답변
Star Strider
2014년 11월 30일
To do an FFT you need to start by converting it to grayscale:
I = imread('sample.jpg');
G = double(rgb2gray(I));
Note that to take the FFT of a matrix M, you need to take the FFT of the transpose of the first FFT, that is
FFT(M) = FFT(FFT(M).').'
The dot operator here (.') takes the simple (not complex conjugate) transpose.
댓글 수: 2
Star Strider
2014년 11월 30일
편집: Star Strider
2014년 11월 30일
My pleasure.
I used ‘FFT’ in the generic sense. I haven’t run your code, but it should produce a matrix as output on the first pass, taking the first Fourier transform of ‘G’. You then need to take the simple transpose of that output matrix and do the Fourier transform on it. That output is the Fourier transform of your image.
추가 답변 (1개)
Guillaume
2014년 11월 30일
편집: Guillaume
2014년 11월 30일
Your jpg image is read as integer ( uint8 most likely) and matlab is not that good at manipulating pure integers as per the error message. The simplest way to solve this is to convert the integers to doubles:
I = double(imread('sample.jpg'));
댓글 수: 3
Guillaume
2014년 11월 30일
It looks like your code assume a square matrix whereas your image is not square.
The reason I say it looks like you assume a square matrix, is because of this line:
N = length(xn);
length returns the size of the largest dimension, and you then use that to build an N*N matrix. If your input is M*N (M<N) you can't multiply it with your Wnk.
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!