Unable to perform assignment because the indices on the left side are not compatible with the size of the right side.
2 views (last 30 days)
Show older comments
So basically I'm trying to run this project, and it doesn't work for me, shows error, but with other code, and similar program it works. Help me out please, I dont understand whats wrong (btw it's not fully written program, but still Im getting that error.)
Unable to perform assignment because the indices on the left side are not compatible with the size of the
right side.
Error in untitled5 (line 9)
av(i)=fa(xv,d(i));
x0=input ('Input x0:');
xn=input ('Input xn:');
xh=input ('Input xh:');
d=input ('Input d:');
e=input ('Input e:');
xv=x0:xh:xn;
[m,n]=size(xv);
for i=1:n
av(i)=fa(xv,d(i));
end
for i=1:n
bv(i)=fb(x,av(i));
end
for i=1:n
cv(i)=fc(a,b,ev(i));
end
7 Comments
Walter Roberson
on 17 Oct 2022
In MATLAB
else (a<=b)
c = cos(e.^a);
is equivalent to
else
(a<=b)
c = cos(e.^a);
Do not follow "else" with a condition.
If you want the else branch to be selectively executed then
elseif (a<=b)
c = cos(e.^a);
You should then be asking yourself under what circumstances could both a>b and a<=b be false that you might want to execute the branch selectively. The answer to that question is both would be false if a or b are nan. Or both could be false if a or b are non-scalar.
Answers (1)
David Hill
on 17 Oct 2022
x0=0;
xn=10;
xh=.1;
d=3;
xv=x0:xh:xn;
av=fa(xv,d);
plot(xv,av)
AV=@(xv,d)d*(xv.^2)-(2*abs(xv))-3;%with a simple function you might just want to make an anonymous function
plot(xv,AV(xv,d))
function a = fa (x,d)
a = d*(x.^2)-(2*abs(x))-3;
end
0 Comments
See Also
Categories
Find more on Loops and Conditional Statements 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!