简体   繁体   English

linprog-“订阅的分配维度不匹配”错误

[英]linprog - “Subscripted assignment dimension mismatch” error

"Subscripted assignment dimension mismatch.' “下标分配尺寸不匹配。' when running a linprog coding. 运行linprog编码时。

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 PV_output为8760x1x27和WT_output为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? 我正在尝试在此代码中找到27和3 PV和WT的所有组合的“ f”系数,有人知道如何索引“ f”吗?

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) 接下来,您不需要(:,M:N) ,而是(:,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. 例如,您不能将不同大小的矩阵加在一起,因此请确保尺寸相同。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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