This function keeps returning the error"ttempted to access wf(2); index out of bounds because numel(wf)=1. "
조회 수: 1 (최근 30일)
이전 댓글 표시
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
답변 (2개)
Roger Stafford
2015년 3월 15일
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
Star Strider
2015년 3월 15일
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
Star Strider
2015년 3월 15일
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.
참고 항목
카테고리
Help Center 및 File Exchange에서 Fortran with MATLAB에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!