Effacer les filtres
Effacer les filtres

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

14 vues (au cours des 30 derniers jours)
Kenneth Yee
Kenneth Yee le 18 Avr 2020
Commenté : Kenneth Yee le 19 Avr 2020
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

Réponses (1)

Mehmed Saad
Mehmed Saad le 18 Avr 2020
Modifié(e) : Mehmed Saad le 18 Avr 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 commentaires
Kenneth Yee
Kenneth Yee le 19 Avr 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 le 19 Avr 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?

Connectez-vous pour commenter.

Catégories

En savoir plus sur Programmatic Model Editing dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by