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 次查看(过去 30 天)
显示 更早的评论
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 个评论
Image Analyst
2018-5-14
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.
回答(1 个)
Walter Roberson
2018-5-14
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.
2 个评论
Walter Roberson
2018-5-15
You could post your model for week7 so that we could examine it to see what should be expected.
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!