Indexing and iteration problem. Few lines holding me back. Please, HELP!
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
I have attached the Delft.mat file. which contains the vectors listed in the code. I removed my progress in the coding so as not to make any complications.
Please note these following formula that will be inputted in the code
alpha = 0.2
am = 90 - theta
cos_AOI = cos(a) x cos (as) x cos (b - As) + sin (a) x sin (As)
Gdirect = DNI x cos_AOI
SVF = (1 + cosd(theta))/2
Gdiffuse = SVF x DHI
Galbedo = GHI x alpha x (1-SVF)
Gm = Gdirect + Gdiffuse + Galbedo
Em = Gm/1000
Em(a,b) is the sum of all values in Matrix Em.
I will be very glad if I am assisted.
% First we load the '.mat' file containing the hourly meteorological data of an entire year per hour into MATLAB's workspace
% The following lines are used to load the meterological data. The variable location_filename can be modified to experiment with data for other locations.
location_filename = 'Delft.mat'; %You can replace 'Delft.mat' by: 'Buenos_Aires.mat'; 'New_Dehli.mat'; or 'Vancouver.mat'
load(location_filename,'As','as','DHI','DNI','GHI')% Loading vectors 'As', 'as', 'DHI', 'DNI' and 'GHI'
alpha = ...; % Albedo coefficient
Am = 0:2:360; % Initializing PV Module Azimuth range from 0-360 degrees in steps of 2 degrees as a row vector
theta = 0:2:90; % Initializing PV Module tilt angle range from 0-90 degrees in steps of 2 degrees as a row vector
am = ...; % PV Module altitude range as a row vector
% Create
for a = 1:1:... %'a' is the index to iterate through vector 'am'
for b = 1:1:... %'b' is the index to iterate through vector 'Am'
% Direct Irradiance
cos_AOI = ... % Calculate the cosine of the angle of incidence for every hour of the year for a specific module tilt and orientation
Gdirect = ...
Gdirect(Gdirect<0) = 0; % This makes all the negative Direct Irradiance on the PV module as zero.
% Isotropic Diffuse Irradiance
SVF = ...
Gdiffuse = ...
% Irradiance due to effect of albedo
Galbedo = ...
% Total Irradinace
Gm = ...
% Total Energy incident on PV module surface for the whole year
Em(a,b) = ...
end % end for loop 2
end % end for loop 1
% Optimum tilt and orientation for PV module
% Hint: find Em_max to get the optimum tilt and orientation angle
Em_max = ...
% Opt_Am is the optimum orientation/Azimuth of the PV module, Opt_theta is the optimum tilt angle of the PV module
Opt_Am = ...
Opt_theta = ...
Below is my attepted code with your suggestion too.
alpha = 0.2; % Albedo coefficient
Am = 0:2:360; % Initializing PV Module Azimuth range from 0-360 degrees in steps of 2 degrees as a row vector
theta = 0:2:90; % Initializing PV Module tilt angle range from 0-90 degrees in steps of 2 degrees as a row vector
am = 90-theta; % PV Module altitude range as a row vector
% Create
for ind_am = 1:1:90 %'a' is the index to iterate through vector 'am'
for ind_Am = 1:1:360 %'b' is the index to iterate through vector 'Am'
a = am(ind_am);
b = Am(ind_Am);
% Direct Irradiance
cos_AOI = (cosd(a).*cosd(as).*cosd(b-As)) + (sind(a).*sind(As)); % Calculate the cosine of the angle of incidence for every hour of the year for a specific module tilt and orientation
Gdirect = DNI .* cos_AOI;
Gdirect(Gdirect<0) = 0; % This makes all the negative Direct Irradiance on the PV module as zero.
% Isotropic Diffuse Irradiance
SVF = (1 + cosd(theta))/2;
Gdiffuse = SVF .* DHI;
Gdiffuse(Gdiffuse<0)= 0;
% Irradiance due to effect of albedo
Galbedo = GHI * alpha * (1-SVF);
% Total Irradinace
Gm = Gdirect + Gdiffuse + Galbedo;
Em = Gm/1000;
% Total Energy incident on PV module surface for the whole year
Em(a,b) = sum(sum(Em));
end % end for loop 2
end % end for loop 1
The response I get is-
Index in position 2 is invalid. Array indices must be positive integers or logical values.
Error in solution (line 33)
Em(a,b) = sum(sum(Em));
30 comentarios
Varun Saini
el 31 de Ag. de 2021
The row for December month is from 8017 to 8760. Shall be we have to make loop for this or we can load the date of file and mak For loop from 01 Dec to 31 Dec
Walter Roberson
el 2 de Oct. de 2021
If the data were read using readtable() and the DateT column were a datetime object, then
[y, m, d] = ymd(TheTable.DateT);
isdecember = m == 12;
DecemberTable = TheTable(isdecember, :);
Respuestas (2)
Walter Roberson
el 16 de Feb. de 2020
Em(a,b) your a and b are floating point numbers which cannot be used as indices.
Em(ind_am, ind_Am)
It is confusing that you use two names that differ just in the a vs A, by the way.
2 comentarios
mehrdad aberoumandazar
el 2 de Oct. de 2021
dear Johnson
hi
would you please share the finle codes?
thanks in advance
Yonten
el 24 de Oct. de 2022
alpha = 0.2; % Albedo coefficient
Am = 0:2:360; % Initializing PV Module Azimuth range from 0-360 degrees in steps of 2 degrees as a row vector
theta = 0:2:90; % Initializing PV Module tilt angle range from 0-90 degrees in steps of 2 degrees as a row vector
am = 90-theta; % PV Module altitude range as a row vector
% Create
for ind_am = 1:1:90 %'a' is the index to iterate through vector 'am'
for ind_Am = 1:1:360 %'b' is the index to iterate through vector 'Am'
a = am(ind_am);
b = Am(ind_Am);
% Direct Irradiance
cos_AOI = (cosd(a).*cosd(as).*cosd(b-As)) + (sind(a).*sind(As)); % Calculate the cosine of the angle of incidence for every hour of the year for a specific module tilt and orientation
Gdirect = DNI .* cos_AOI;
Gdirect(Gdirect<0) = 0; % This makes all the negative Direct Irradiance on the PV module as zero.
% Isotropic Diffuse Irradiance
SVF = (1 + cosd(theta))/2;
Gdiffuse = SVF .* DHI;
Gdiffuse(Gdiffuse<0)= 0;
% Irradiance due to effect of albedo
Galbedo = GHI * alpha * (1-SVF);
% Total Irradinace
Gm = Gdirect + Gdiffuse + Galbedo;
Em = Gm/1000;
% Total Energy incident on PV module surface for the whole year
Em(a,b) = sum(sum(Em));
end % end for loop 2
end % end for loop 1
0 comentarios
Ver también
Categorías
Más información sobre Modulation en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!