简体   繁体   中英

linprog - “Subscripted assignment dimension mismatch” error

"Subscripted assignment dimension mismatch.' when running a linprog coding.

My code is

for M = 1 : size(PV_output,1)
for N = 1 : size(WT_output,2)


    f(:,M:N ) = [((CRF*CC_PV(M)/PVenergy(M)+OM_PV)); ((CRF*CC_WT(N))/WTenergy(N))+OM_WT];  % Objective function coefficients

    %A(:,:) = [-PV_output(:,:,K)  -WT_output(:,:,L)];
    A (:,M,N) = [-PV_output(:,M)  -WT_output(:,N) ];

    b(:,:)  = -Demand(:);

    lb = zeros(2,1);

    ub = [max_PV_area/PV_area; max_WT_area/WT_area]';

end
end 
[x, fval, exitflag] = linprog(f,A,b,[],[],lb,ub)

PV_output is 8760x1x27 and WT_output is 8760x1x3

I am trying to find the "f" coefficients below for all the combinations of the 27 and 3 PV and WT's in this code Does anyone know how to index the "f" to do so?

Thank you

Your first problem is that you need to get size of the third dimension of the matrices:

for M = 1 : size(PV_output,3) %# <---3, not 1  
    for N = 1 : size(WT_output,3) %# <---3, not 1 

Next, you don't want (:,M:N) but rather (:,M,N)

f(:,M,N)

There is likely more. This should get you started; and use the debugger to see what sizes the dimensions of your matrices are, and make sure they are what you think they should be. For example, you can't add matrices of different sizes together, so make sure the dimensions are the same.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM