n an assignment A(I) = B, the number of elements in B and I must be the same. why is this?

N = 10;
G = zeros(1,N);
dx12 = zeros(1,N);
dx22 = zeros(1,N);
alpha12 = zeros(1,N);
alpha22 = zeros(1,N);
a = zeros(1,N);
b = zeros(1,N);
X = [a b];
c = zeros(1,N);
d = zeros(1,N);
U = [c d];
a(1) = x12;
b(1) = x22;
c(1) = u12;
d(1) = u12;
BETA = zeros(1,N);
BETA(1) = beta1;
for i = 1:N
G(i) = feval('performance4_3a',a(i),b(i));
dx12(i) = feval('derivative_dx1',a(i),b(i));
dx22(i) = feval('derivative_dx2',a(i),b(i));
BETA(i) = (G-((dx12*sigma(1)*u12)+(dx22*sigma(2)*u22)))/ ...
(sqrt((dx12*sigma(1)).^2+(dx22*sigma(2)).^2));
alpha12(i) = -(dx12*sigma(1))/(sqrt((dx12*sigma(1)).^2 + ...
(dx22*sigma(2)).^2));
alpha22(i) = -(dx22*sigma(2))/(sqrt((dx12*sigma(1)).^2+ ...
(dx22*sigma(2)).^2));
for ii = 1:N
a(ii) = x(1)+BETA.*alpha12.*sigma(1);
b(ii) = x(2)+BETA.*alpha22.*sigma(2);
c(ii) = (a(ii)-x(1))./sigma(1);
d(ii) = (b(ii)-x(2))./sigma(2);
end
end

1 Comment

The answer to the question posed is that otherwise there's no way to align the RHS content to the LHS. If the LHS is undeclared then dynamic allocation can take place, but if you define the target as you have here by using subscripts (which are single values here, btw, in all instances) then there's only one place to put a single value (unless the RHS is a cell reference in which case the LHS cell can hold the content of the RHS, but again, that's not what you're showing here.
W/o the error in context we can't tell where the error actually occurred and without the missing functions can't run the code to find out...
But, as shown the output of each has to be a single-valued function.

Answers (0)

This question is closed.

Tags

Asked:

on 11 Dec 2014

Closed:

on 20 Aug 2021

Community Treasure Hunt

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

Start Hunting!