This function keeps returning the error"ttempted to access wf(2); index out of bounds because numel(wf)=1. "
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
This function keeps returning this error and I cannot figure out how to fix it. Can anyone help?
function Powerval=Analyse_Grid(wf)
global wind_farm;
global N;
global velocity_farm;
N = 30;
wind_farm = zeros(N,2);
velocity_farm = zeros(N,1);
wf = wf * 1000;
wf = round(wf);
for a = 1:1:N
b = (2 * a) - 1;
wind_farm(a,1) = wf(b);
wind_farm(a,2) = wf(b + 1);
end
power = 0;
total_power = 0;
wind_farm = sortrows(wind_farm,[2 1]);
for i = 1:1:N
x = wind_farm(i,1);
y = wind_farm(i,2);
velocity = check_wake(x,y,i);
velocity_farm(i) = velocity;
power = 0.3 * (velocity ^ 3);
total_power = total_power + power;
end
0 Kommentare
Antworten (2)
Roger Stafford
am 15 Mär. 2015
Matlab states that the number of elements it finds in 'wf' is 1. It must mean that you passed a scalar 'wf' to 'Powerval' when you called on it. You had better check on how you called on it, because your code within the first for-loop calls for it to have at least 60 elements in it.
0 Kommentare
Star Strider
am 15 Mär. 2015
You have defined ‘wf’ as an input argument. What are you supplying to it in your call to ‘Analyse_Grid’?
It wants a vector of length (2*N-1), that since you defined ‘N=30’, would be 59.
At least that’s how I interpret your code.
4 Kommentare
Star Strider
am 15 Mär. 2015
My pleasure!
I don’t know how you’re using it in GA. If ‘wf’ is a ‘chromosome’ (or ‘individual’), then it needs to be a vector, and possibly a vector of parameters. The GA algorithm then optimises the parameters according to your designated ‘fitness function’.
I don’t have significant recent experience with the MATLAB GA functions (I wrote a number of my own in FORTRAN ‘way back when), so I would be reluctant to advise you specifically on the rest of your code, but consider that if ‘Analyse_Grid’ is your fitness function (or called by it), ‘wf’ nevertheless needs to be a vector.
Siehe auch
Kategorien
Mehr zu Fortran with MATLAB finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!