47 views (last 30 days)

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));

Walter Roberson
on 16 Feb 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.

Opportunities for recent engineering grads.

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

Start Hunting!
## 25 Comments

## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/505731-indexing-and-iteration-problem-few-lines-holding-me-back-please-help#comment_797870

⋮## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/505731-indexing-and-iteration-problem-few-lines-holding-me-back-please-help#comment_797870

## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/505731-indexing-and-iteration-problem-few-lines-holding-me-back-please-help#comment_797874

⋮## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/505731-indexing-and-iteration-problem-few-lines-holding-me-back-please-help#comment_797874

## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/505731-indexing-and-iteration-problem-few-lines-holding-me-back-please-help#comment_797876

⋮## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/505731-indexing-and-iteration-problem-few-lines-holding-me-back-please-help#comment_797876

## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/505731-indexing-and-iteration-problem-few-lines-holding-me-back-please-help#comment_797878

⋮## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/505731-indexing-and-iteration-problem-few-lines-holding-me-back-please-help#comment_797878

## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/505731-indexing-and-iteration-problem-few-lines-holding-me-back-please-help#comment_797884

⋮## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/505731-indexing-and-iteration-problem-few-lines-holding-me-back-please-help#comment_797884

## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/505731-indexing-and-iteration-problem-few-lines-holding-me-back-please-help#comment_797886

⋮## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/505731-indexing-and-iteration-problem-few-lines-holding-me-back-please-help#comment_797886

## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/505731-indexing-and-iteration-problem-few-lines-holding-me-back-please-help#comment_798210

⋮## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/505731-indexing-and-iteration-problem-few-lines-holding-me-back-please-help#comment_798210

## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/505731-indexing-and-iteration-problem-few-lines-holding-me-back-please-help#comment_798214

⋮## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/505731-indexing-and-iteration-problem-few-lines-holding-me-back-please-help#comment_798214

## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/505731-indexing-and-iteration-problem-few-lines-holding-me-back-please-help#comment_798219

⋮## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/505731-indexing-and-iteration-problem-few-lines-holding-me-back-please-help#comment_798219

## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/505731-indexing-and-iteration-problem-few-lines-holding-me-back-please-help#comment_798221

⋮## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/505731-indexing-and-iteration-problem-few-lines-holding-me-back-please-help#comment_798221

## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/505731-indexing-and-iteration-problem-few-lines-holding-me-back-please-help#comment_798222

⋮## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/505731-indexing-and-iteration-problem-few-lines-holding-me-back-please-help#comment_798222

## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/505731-indexing-and-iteration-problem-few-lines-holding-me-back-please-help#comment_798223

⋮## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/505731-indexing-and-iteration-problem-few-lines-holding-me-back-please-help#comment_798223

## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/505731-indexing-and-iteration-problem-few-lines-holding-me-back-please-help#comment_798225

⋮## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/505731-indexing-and-iteration-problem-few-lines-holding-me-back-please-help#comment_798225

## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/505731-indexing-and-iteration-problem-few-lines-holding-me-back-please-help#comment_798231

⋮## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/505731-indexing-and-iteration-problem-few-lines-holding-me-back-please-help#comment_798231

## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/505731-indexing-and-iteration-problem-few-lines-holding-me-back-please-help#comment_798238

⋮## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/505731-indexing-and-iteration-problem-few-lines-holding-me-back-please-help#comment_798238

## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/505731-indexing-and-iteration-problem-few-lines-holding-me-back-please-help#comment_798248

⋮## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/505731-indexing-and-iteration-problem-few-lines-holding-me-back-please-help#comment_798248

## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/505731-indexing-and-iteration-problem-few-lines-holding-me-back-please-help#comment_798253

⋮## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/505731-indexing-and-iteration-problem-few-lines-holding-me-back-please-help#comment_798253

## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/505731-indexing-and-iteration-problem-few-lines-holding-me-back-please-help#comment_798300

⋮## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/505731-indexing-and-iteration-problem-few-lines-holding-me-back-please-help#comment_798300

## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/505731-indexing-and-iteration-problem-few-lines-holding-me-back-please-help#comment_798302

⋮## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/505731-indexing-and-iteration-problem-few-lines-holding-me-back-please-help#comment_798302

## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/505731-indexing-and-iteration-problem-few-lines-holding-me-back-please-help#comment_798310

⋮## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/505731-indexing-and-iteration-problem-few-lines-holding-me-back-please-help#comment_798310

## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/505731-indexing-and-iteration-problem-few-lines-holding-me-back-please-help#comment_798354

⋮## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/505731-indexing-and-iteration-problem-few-lines-holding-me-back-please-help#comment_798354

## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/505731-indexing-and-iteration-problem-few-lines-holding-me-back-please-help#comment_799724

⋮## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/505731-indexing-and-iteration-problem-few-lines-holding-me-back-please-help#comment_799724

## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/505731-indexing-and-iteration-problem-few-lines-holding-me-back-please-help#comment_799750

⋮## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/505731-indexing-and-iteration-problem-few-lines-holding-me-back-please-help#comment_799750

## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/505731-indexing-and-iteration-problem-few-lines-holding-me-back-please-help#comment_800291

⋮## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/505731-indexing-and-iteration-problem-few-lines-holding-me-back-please-help#comment_800291

## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/505731-indexing-and-iteration-problem-few-lines-holding-me-back-please-help#comment_1001944

⋮## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/505731-indexing-and-iteration-problem-few-lines-holding-me-back-please-help#comment_1001944

Sign in to comment.