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

조회 수: 1 (최근 30일)
"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

채택된 답변

Sean de Wolski
Sean de Wolski 2012년 6월 21일
Huh?
You could squeeze() it to remove the singleton dimension.
  댓글 수: 7
Sean de Wolski
Sean de Wolski 2012년 6월 21일
So why are they 3d matrices and not just two, considering that there is only 1 column and thus it is essentially a 2d matrix permuted into the third dimension?
And, what you have here is _exactly_ what I said in my reply, if m, n are 1.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Andrew Alkiviades
Andrew Alkiviades 2012년 6월 21일
If I have understood correctly, I have adapted my code to your suggestions
A = cell(27,3);
for ii = 1:27
PV = PV_output(:,:,ii);
for jj = 1:3
WT = WT_output(:,:,ii);
A(ii,jj) = [PV WT];
f = [((CRF*CC_PV(PV)/PVenergy(PV)+OM_PV)); ((CRF*CC_WT(WT))/WTenergy(WT))+OM_WT]; % Objective function coefficients
end
end
I am not sure of the
A(ii,jj) = [PV WT];
as it stands i have an error on the A(ii,jj) = [PV WT] line of "Conversion to cell from double is not possible." What alterations can I make to "A" that will allow me to directly use it as the inequality constraint matrix in linprog? I require A to be a 8760x2x81 matrix - if so can this matrix be used in the Ax<=b form that linprog requires so that I can optimise and select from all the PV and WT combinations?
  댓글 수: 4
Sean de Wolski
Sean de Wolski 2012년 6월 21일
That was a typo, you will want:
A{ii,jj}, note the xcurly '{' which indicates conversion. The regular parenthesis assumes it is a cell already and that is why you see the error.
Andrew Alkiviades
Andrew Alkiviades 2012년 6월 21일
Thanks, I think we are getting there!
I can run without errors on these lines but I can access any array or element in A, when I run for A i get
A = [8760x2 double] [ ] [ ] for 27 rows which I am assuming is all the array combinations possible?

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by