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

"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 日

0 投票

Huh?
You could squeeze() it to remove the singleton dimension.

7 件のコメント

Andrew Alkiviades
Andrew Alkiviades 2012 年 6 月 21 日
sean, please be more specific, Im not sure I understand your question?
Am I correct in thinking "f" needs an index (e.g f(:,M) for example??)
how can I index the line of code for "f=..." to get all the combinations between the 27 PV's and 3 WT's?
i.e a total of 81 different combinations?
Sean de Wolski
Sean de Wolski 2012 年 6 月 21 日
I don't understand what you ware ttrying to do. It would be much cleared if you could use small matrices that we can reproduce on our end. My thinking is that you are indexing into a 2d matrix with a 3d or vice-versa. Thus if you squeeze the 3d matrix to remove the second dimension (which is 1), it might resolve your issue. Just a thought.
Andrew Alkiviades
Andrew Alkiviades 2012 年 6 月 21 日
both PV_output and WT_output are 3 dimensional (but PV has 27 "sets" and WT has 3 "sets")
All I am trying to do is find the coding format for "f" and "A" matrices that will allow me to simultaneously run the optimisation for all the combinations of the 27 and 3 matrices (i.e in total 81)
Hope this is clearer and helps
Sean de Wolski
Sean de Wolski 2012 年 6 月 21 日
So one is size (m,n,27), the other (m,n,3);
And you want essentially run two for-loops:
C = cell(27,3);
for ii = 1:27
A = x1(:,:,ii);
for jj = 1:3
B = x2(:,:,ii);
C(ii,jj) = something_with(A,B)
end
end
?
Andrew Alkiviades
Andrew Alkiviades 2012 年 6 月 21 日
no, one size is (8760,1,m) and the other is (8760,1,n)
and I want to code "f" and "A" matrices for all the m and n combinations.
where m is 27 and n is 3
hope this is clearer
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.
Sean de Wolski
Sean de Wolski 2012 年 6 月 21 日
(*) m is 8760, n is 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 件のコメント

Andrew Alkiviades
Andrew Alkiviades 2012 年 6 月 21 日
I have concatenated PV and WT horizontally and have a size(A) 27 x 3 (which is expected since it is 27x3 arrays right?)
Andrew Alkiviades
Andrew Alkiviades 2012 年 6 月 21 日
However, matlab doesn't like this concatenation as I get the "Conversion to cell from double is not possible.
" error!
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?

サインインしてコメントする。

カテゴリ

Community Treasure Hunt

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

Start Hunting!

Translated by