Filter löschen
Filter löschen

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

14 Ansichten (letzte 30 Tage)
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

Antworten (1)

Mehmed Saad
Mehmed Saad am 18 Apr. 2020
Bearbeitet: Mehmed Saad am 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 Kommentare
Kenneth Yee
Kenneth Yee am 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 am 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?

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Programmatic Model Editing finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by