How can I fix this code and run it? Please! Index exceeds matrix dimensions. Error in AccelerationWeek10 (line 28) s = s(1:npts/2+1); % truncate (removes complex conjugates) Published with MATLAB® R2017b

1 view (last 30 days)
Simulink and Matlab code
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
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]')
m =
500
naturalFr =
44.7214
Warning: Cannot find an exact case-sensitive match for the model or library name
'<a href="matlab:open_system ('week7')">week7</a>'.
Using the closest case-insensitive match: '<a href="matlab:open_system
('Week7')">Week7</a>'.
Case-insensitive matching will be removed in a future release. Specify exact
case instead.
Warning: Output port 1 of '<a href="matlab:open_and_hilite_hyperlink
('Week7/Signal Generator','error')">Week7/Signal Generator</a>' is not
connected.
Warning: Output port 1 of '<a href="matlab:open_and_hilite_hyperlink
('Week7/Sine Wave1','error')">Week7/Sine Wave1</a>' is not connected.
Warning: Input port 1 of '<a href="matlab:open_and_hilite_hyperlink ('Week7/To
Workspace','error')">Week7/To Workspace</a>' is not connected.
Warning: Input port 1 of '<a href="matlab:open_and_hilite_hyperlink ('Week7/To
Workspace2','error')">Week7/To Workspace2</a>' is not connected.
Index exceeds matrix dimensions.
Error in AccelerationWeek10 (line 28)
s = s(1:npts/2+1); % truncate (removes complex conjugates)
Published with MATLAB&reg; R2017b

Answers (0)

Categories

Find more on Event Functions in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!