Problems with a nested For Loop and max value
Mostrar comentarios más antiguos
Currently I am working with a table containing the hourly meteorological data, specifically related with the sun position during a certain year. My table contains a cell array constituted by 6 structures: ‘Time (hour)’, ‘As’, ‘as’, ‘DHI’, ‘DNI’, ‘GHI’. Each structure contains a bit more of 8000 fields representing the data at each hour of an entire year. My objective is to calculate the tilt angle (theta) and orientation of a PV module (Azimuth of the module, Am), by optimizing them for a full year time period. To do so, I need to use a nested for loop, in order to determine at which theta and Am values the maximum energy values is received by the module. I’ve used the following code:
location_filename = 'Delft.mat';
load(location_filename,'As','as','DHI','DNI','GHI') % Loading vectors 'As', 'as', 'DHI', 'DNI' and 'GHI'
alpha = 0.2;
Am = 0:2:360;
theta = 0:2:90;
am = 90-theta;
for a = 1:length(am)
for b = 1:length(Am)
cos_AOI = cosd(am(a)).*cosd(as).*cosd(Am(b)-As)+(sind(am(a)).*sind(as));
Gdirect = DNI.*cos_AOI; % I obtained a column vector of 8700x1
Gdirect(Gdirect<0) = 0;
SVF = (1+cosd(theta))/2;
Gdiffuse = SVF.*DHI;
Galbedo = GHI.*alpha.*(1-SVF);
% Total Irradinace
Gm = Gdirect+Gdiffuse+Galbedo; % Here I obtained an array of 8700x46
%%%% {Total Energy: First, Gm is expressed in Watts(W), but I need to calculate the total energy received during the whole year at each theta and Am values. So, I think I should sum up all the rows of each column from the resulting Gm array. Thus, I would obtain the total energy in W-hour units for the whole year}%%
Em(a,b) = sum(Gm,1); % ERROR! “Subscripted assignment dimension mismatch”
end
end
% Optimum tilt and orientation for PV module
[Em_max,I] = max(Em(:))
% tilt angle of the PV module
[I_row,I_col] = ind2sub(size(Em),I)
% This will give me the row and the column index of Em array, but how do I know if they are the coordinates for Opt_theta or Opt_Am?
Opt_Am = %I don’t know how I could associate the index values for determine theta and Am.
Opt_theta =
I know that I have a mistake in my nested For Loop but I really can’t figure out what is wrong in my code. If some one can give me some comments in order to solve this problem I would be very grateful. Thanks in advance!!
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Loops and Conditional Statements en Centro de ayuda y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!