In an assignment A(:) = B, the number of elements in A and B must be the same.

1 view (last 30 days)
My code is:
pvals = 10:1:15;
nump = length(pvals);
for pidx = 1 : nump
p=pvals(pidx);
[x(pidx),y(pidx)]=solve('9*x(pidx)+8*y(pidx)=p','13*x(pidx)+14*y(pidx)=p+2','x(pidx)','y(pidx)');
end
plot(pvals,x)
The error is:
In an assignment A(:) = B, the number of elements in A and B must be the same.
Any help is appreciated! Thanks!
  4 Comments
Kevin Phung
Kevin Phung on 23 Jan 2019
unfortunately I don't have the toolbox, so I cant actually run your code :( sorry

Sign in to comment.

Accepted Answer

Star Strider
Star Strider on 23 Jan 2019
My version of the Symbolic Math Toolbox doesn’t like quoted strings, so I had to change your code a bit.
Try this:
syms p x y
pvals = 10:1:15;
nump = length(pvals);
for pidx = 1 : nump
p=pvals(pidx);
[xs(pidx),ys(pidx)]=solve([9*x+8*y==p, 13*x+14*y==p+2], [x y]);
end
plot(pvals,xs)
  6 Comments

Sign in to comment.

More Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!