How to solve "Attempted to access index 0 of an array with smaller dimension sizes.

14 views (last 30 days)
I'm trying to compare current data with previous data like data(i)-data(i-1) in simulink. 'b' is the input from workspace where i had transfer the data from excel. When i run the simulink the error as stated in the title occured. Anyone here know how to solve?
function [y,z]= fcn(b)
% b=current input PV power,
%y= power fluctuation, z=smoothed output
for i = 1:1440;
y = (b(i))-(b(i-1))/6240*100;
if (y>10)
z = b(i-1) - [(abs(y-10))*6240/100];
elseif (y<-10)
z=b(i-1) + [(abs(y+10))*6240/100];
else
z = b(i);
end
end

Answers (1)

Mehmed Saad
Mehmed Saad on 18 Apr 2020
Edited: Mehmed Saad on 18 Apr 2020
function [y,z]= fcn(b)
% b=current input PV power,
%y= power fluctuation, z=smoothed output
for i = 2:length(b);
y = (b(i))-(b(i-1))/6240*100;
if (y>10)
z = b(i-1) - [(abs(y-10))*6240/100];
elseif (y<-10)
z=b(i-1) + [(abs(y+10))*6240/100];
else
z = b(i);
end
end
  25 Comments
Kenneth Yee
Kenneth Yee on 19 Apr 2020
Yes, I had insert the excel data before run the simulink. Just the data after going through delay block is not what i wanted then the whole output become incorrect. As I thought, the delay block will just delay the input data one time step but its not.
Kenneth Yee
Kenneth Yee on 19 Apr 2020
I had tried the latest one. What i want from the delay block is delay one time step compare to the original data, but what i get from the delay block is advance one time step. The data i want, for example, the original data at 694th is 4607.79, the data i want to get after the delay block at 693th is 4607.79.
You understand what i mean?

Sign in to comment.

Categories

Find more on Programmatic Model Editing in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!