Here is a general way.
If you use the following codes, you will get a warnings
x = []
for i = 1:10
x(i) = sin(i);
end
x = []
for i = 1:10
x = [x sin(i)]
end
You can solve the warning by pre-allocating and use indexing to assign elements
x = zeros(1, 10)
for i = 1:10
x(i) = sin(i);
end
For your code, following will work
current_path = pwd;
tic
load DATA_HILL.mat
PV_MAX_=zeros(12,1);
DEV_PV_=zeros(12,1);
SOC_=zeros(12,1);
month_=zeros(12,1);
PV_irr_=zeros(12,1);
Dev_2_=zeros(12,1);
z=zeros(12,6);
for month_number=1:12
sim('HILL_V2.slx')
disp(month_number);
bdclose('HILL_V2.slx');
load Power_PV.mat
load SOC.mat
load month
load Irr
format Eng
PV_MAX=max(Power_PV);
DEV_PV= (PV_MAX/189000)*100;
SOC= min(SOC);
m=mean(month);
PV_irr=max(Irr)*189;
Dev_2=(1-(PV_MAX/PV_irr))*100;
PV_MAX_(i)=PV_MAX
DEV_PV_(i)=DEV_PV;
SOC_(i)=SOC;
month_(i)=m;
PV_irr_(i)=PV_irr;
Dev_2_(i)=Dev_2;
cd(current_path);
end
A=flip([month_ SOC_ PV_MAX_ DEV_PV_ PV_irr_ Dev_2_].*z);
LastName=flip({'Jan';'Feb';'Mar';'Apr';'May';'Jun';'Jul';'Aug';'Sep';'Oct';'Nov';'Dec'});
T=table(month_, SOC_, PV_MAX_, DEV_PV_, PV_irr_, Dev_2_,...
'RowName', LastName);
disp(T)
toc
Best Answer