Array indices must be positive integers or logical values.

2 vues (au cours des 30 derniers jours)
Joanan Destin
Joanan Destin le 4 Nov 2020
Commenté : Star Strider le 5 Nov 2020
%% I am trying to replicate someone's work and using the flowchart attached and the formula provided I got this code.
% I get this error the I run it" Array indices must be positive integers or logical values. Error in villalva10 (line 74) err2 = ((Vmp+(Rs*Imp))/(Ig-Imp-Isat((exp(1)*(q*(Vmp+(Rs*Imp))/n*k*T)-1))))- Rsh;
Error in villalva10 (line 74)
err2 = ((Vmp+(Rs*Imp))/(Ig-Imp-Isat((exp(1)*(q*(Vmp+(Rs*Imp))/n*k*T)-1))))- Rsh;
clc
close all
clear
% Data provided
load('SD_Test_Data_01.mat', 'voltage')
load('SD_Test_Data_01.mat', 'current')
I = current;
V = voltage;
P = I.*V; % To find the P-V curve
Pmaxcurve = max(P);
% Graphs
figure(1);
plot (V, I,'b:')
xlabel('Voltage (V)'), ylabel('Current (A)')
title('I-V Curve')
figure(2);
plot(V, P,'r--');
xlabel('Voltage(V)'), ylabel('Power (W)')
title('P-V Curve')
figure(3);
plot (V, I,'--')
title('Combine Plots')
hold on
plot(V, P, 'r:');
hold off
% %At the standard test conditions (STC)
[Pmax, index_of_Pmax] = max(P);
Imp = I(index_of_Pmax); %(A)
Vmp = V(index_of_Pmax); %(v)
Isc = max(I); %(A)
Voc = max(V); %(V)
% Maximum power output
% Pmp = Imp * Vmp;
Pmp = Pmax;
% Ig is the light-generated current
% Io = Isat is the diode reverse saturation current
% Rs, Rp are the series and the parallel resistances
n = 1.2; % Ideality factor technology Si-mono
q = 1.6022e-19; %q is the electron charge
K = 1.3806e-23; % k is the Boltzmann constant in (J/k)
% if the solar cells inside a solar module reach 65?C
T = 65; % T the module temperature ?C
Tr = 25; % Reference temperature ?C
% Temperature coefficient of the maximum output power (Pmax ) at STC (%/?C)
k = -0.41;
Ns = 72; % Ns is the number of series connected cells forming the PV module
Rs = 0;
S = 1000; % Irradiance w/m^2
% At short circuit point (V = 0); I = Isc
Ig = Isc;
% Vt is the thermal voltage
Vt = (Ns*n*K*T)/q;
% Solve for I(sat), the reverse saturation current of the diode.
Isat = Ig /(exp(1).^(Voc/Vt) - 1);
% Calculate Rp = Rp,min
Rsh = (Vmp/(Isc - Imp)) - ((Voc - Vmp)/Imp);
% Voltage and current w.r.t. Voc >= V>= 0
V = Vmp((Vmp>=0) & (Vmp<=Voc));
I = Isc((Vmp>=0) & (Vmp<=Voc));
tol = 1e-4;
err1 = ((Vmp/Imp)-(((Ns*n*K*T)/q)*Rsh)/(Isat*Rsh*(exp(1)*(q*(Vmp+(Rs*Imp))/n*k*T)-1))-((n*K*T)/q))- Rs;
err2 = ((Vmp+(Rs*Imp))/(Ig-Imp-Isat((exp(1)*(q*(Vmp+(Rs*Imp))/n*k*T)-1))))- Rsh;
err3 = ((Rsh + Rs)*(Isc-Ig)/Rsh);
err = (err1)^2 + (err3)^2; % err2^2
while(err>tol)
% Sol Eq (7),(15) and (16)
Ig = (Isc + k*(T - Tr))*(S/1000); % Eq(7)
% Pmp,model = Pmp,curve = Vmp Imp at the MPP (Vmp , Imp ) of the I?V curve
Rsh = Vmp*(Vmp+(Rs*Imp))/((Vmp*(Ig - Isat*(exp(Vmp+(Rs*Imp)/Vt))-1)) - Vmp*Imp); % Eq(15)
Ig = ((Rsh + Rs)/Rsh)*Isc; % Eq(16)
% The output current of the single diode model is a function of the output voltage
I = Ig - Isat*(exp((V + (I*Rs))/Rsh)-1) - (V + (I*Rs))/Rsh; %Eq(1)
% Solve for I(sat), the reverse saturation current of the diode.
Isat = (Ig - (Voc/Rsh))/(exp(Voc/Vt) - 1); % Eq(9) for Voc >= V>= 0
P = V*I;
% finding Pmax,model using max(P)
Pmax = max(P);
% calculating error
err = abs(Pmax - Pmaxcurve);
delRs = 1e-6;
% Change in resistance not defined neither described
Rs = Rs + delRs;
disp(Rs)
disp(Rsh)
end

Réponse acceptée

Star Strider
Star Strider le 4 Nov 2020
The problem is:
err2 = ((Vmp+(Rs*Imp))/(Ig-Imp-Isat((exp(1)*(q*(Vmp+(Rs*Imp))/n*k*T)-1))))- Rsh;
↑ ← HERE
Note that ‘Isat’ is a scalar, and in any event cannot be referenced with anything other than integers greater than 0 or logical vectors. I suspect this:
err2 = ((Vmp+(Rs*Imp))/(Ig-Imp-Isat.*((exp(1)*(q*(Vmp+(Rs*Imp))/n*k*T)-1))))- Rsh;
↑ ← MULTIPLICATION(?)
is intended, although it could be any valid operator.
MATLAB does not recognise implicit multiplication.
  2 commentaires
Joanan Destin
Joanan Destin le 4 Nov 2020
Thanks, it works now.
Star Strider
Star Strider le 5 Nov 2020
As always, my pleasure!

Connectez-vous pour commenter.

Plus de réponses (0)

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by