MATLAB: How to create magnitude spectrum signal based on data from excel

fftmagnitude spectrum

dataset=xlsread('Group3.xlsx','Sheet1','A1:ALM1');
stepsize=0.001;
N=1;
t=0:stepsize:N;
x= dataset;
X=fft(x);
f=size(x,2)/2;
mag_spec=abs(x)/f;
freq=(0:499/2*f*stepsize);
plot(freq,mag_spec(1:500));
i already tried this code, but the error state :
'Error using plot
Vectors must be the same length.'

Best Answer

Your code needs a few slight improvements:
dataset=xlsread('Group3.xlsx','Sheet1','A1:ALM1');
stepsize=0.001;
N=1;
t=0:stepsize:N;
x= dataset;
X=fft(x);
f=size(x,2)/2;
mag_spec=abs(X)/(2*f); % Normalise By The Length Of The Original Vector
freq=(0:499*(2*f)*stepsize); % Use Full Vector Length To Create A Compatible Frequency Vector
figure
plot(freq,mag_spec(1:500));
xlim([0 50])