Clear Filters
Clear Filters

How can I make this work Please? In AccelerationWeek10 (line 10) Index exceeds matrix dimensions. Error in AccelerationWeek10 (line 31) s = s(1:npts/2+1); % truncate (removes complex conjugates)

1 view (last 30 days)
close all
npts = 2^15;
sfreq = 22150;
dt = 1/sfreq;
t = (0:npts-1)'*dt;
m = 500 % mass
k = 1000000;
c= 1000;
naturalFr = sqrt(k/m)
sim('week7')% Simulink
figure(1)
plot(Accel)
xlabel('Time [s]')
ylabel('Signal [units]')
s = fft(Accel.Data);%3
figure(2)
subplot(211)
plot(real(s))
grid on
xlabel('Index')
ylabel('Real')
subplot(212)
plot(imag(s))
grid on
xlabel('Index')
ylabel('Real')
% % folding and scaling
Line 31 s = s(1:npts/2+1); % truncate (removes complex conjugates)
s = s/npts; % scale
s(2:end-1) = 2* s(2:end-1); % fold 6
df = sfreq/npts;
freq = (0:npts/2)'*df;
mag = abs(s);% 7
% mag1 = sqrt(imag(s).^2+real(s).^2);%
mag1 = atan(imag(s)/real(s));
figure(3)
plot(freq,mag)
hold on
plot(freq,mag1)
grid on
xlabel('Frequency [Hz]')
ylabel('Magnitude [units]')
  2 Comments
Image Analyst
Image Analyst on 14 May 2018
Line 10 is
sim('week7')% Simulink
NOT
s = s(1:npts/2+1); % truncate (removes complex conjugates)
Please explain the discrepancy. Please post the actual code you are using because I'm not sure, because of the line number discrepancy, what code you're actually running.

Sign in to comment.

Answers (1)

Walter Roberson
Walter Roberson on 14 May 2018
As outsiders, we have no reason to expect that your call to sim('week7') will produce an Accel.Data that happens to be at least npts/2+1 long.

Community Treasure Hunt

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

Start Hunting!