필터 지우기
필터 지우기

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

채택된 답변

Star Strider
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
alladin
alladin 2014년 11월 30일
Thank you for your help; however, I'm trying to implement 1 dimensional dft here without using matlab built-in functions. can you please help me resolve the issue?
Star Strider
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
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
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 CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by