CVX: In an assignment A(:) = B, the number of elements in A and B must be the same.
조회 수: 2 (최근 30일)
이전 댓글 표시
Hi all,
I am very new to Matlab and CVX. I have only been using them for the last few months and my background is in engineering not mathematics. I am having the following problem. I am trying to minimise the following objective function:
sum(sum_square(p1(:,2:30)-p1(:,1:29)))
Based on the requirements of the following equations:
for i = 1:29
V = 900;
CL(i) = (W(i).*g)/(0.5*density*(V^2)*S);
CD(i) = CDo + ((CL(i).^2)/(3.14*AR*e));
T = ((CD(i)/CL(i))*(W(i)*g))/1000; %convert to KN
cp(i) = {p1(1,i), p1(2,i); p1(1,i+1), p1(2,i+1)};
disp(i) = pdist(cp(i),'euclidean')*1000; %convert to m
Wf(i) = SFC*T*(disp(i)/V);
W(i+1) = W(i)-Wf(i);
end
Given variables: W, g, V, S, CDo, SFC, density
When I run this I get the following error:
Error using cvx/subsasgn (line 39)
In an assignment A(:) = B, the number of elements in A and B must be the same.
Error in fueloptimal (line 79) cp(i) = {p1(1,i), p1(2,i); p1(1,i+1), p1(2,i+1)};
Can anybody help me with this problem?
Thank you in advance.
댓글 수: 0
채택된 답변
Image Analyst
2014년 9월 25일
In this line
cp(i) = {p1(1,i), p1(2,i); p1(1,i+1), p1(2,i+1)};
you're setting cp(i) to a cell. That's what the braces mean - it's a cell. Inside the cell you can have an array, a string, a structure, another cell, just about anything. See the FAQ for a good intuitive explanation: http://matlab.wikia.com/wiki/FAQ#What_is_a_cell_array.3F
But you can't have p1(1,i), p1(2,i); p1(1,i+1), p1(2,i+1) inside a cell because that's not an array. Those values need to be enclosed by brackets to turn them into an array. And once they're an array, THEN you can stick them into a cell and make that the i'th cell of the cell array called "cp". Understand? You will if you read the FAQ.
I'll do it in two steps just to be explicit:
thisArray = [p1(1,i), p1(2,i); p1(1,i+1), p1(2,i+1)];
cp(i) = {thisArray}; % Equivalent to cp{i} = thisArray;
댓글 수: 7
Image Analyst
2014년 9월 29일
편집: Image Analyst
2014년 9월 29일
What is CVX? I don't have enough information or code to run this, so until we have that we can't help.
I'm not going to download that and install it, so just give nominal values for all those variables you have so we have something that will at least run without saying "W undefined", etc.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Startup and Shutdown에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!