CVX: In an assignment A(:) = B, the number of elements in A and B must be the same.
2 views (last 30 days)
Show older comments
Zena Assaad
on 25 Sep 2014
Commented: Zena Assaad
on 30 Sep 2014
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 Comments
Accepted Answer
Image Analyst
on 25 Sep 2014
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 Comments
Image Analyst
on 29 Sep 2014
Edited: Image Analyst
on 29 Sep 2014
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.
More Answers (0)
See Also
Categories
Find more on Startup and Shutdown in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!