why is this program keep telling me this error: Unable to perform assignment because the left and right sides have a different number of elements.

조회 수: 1 (최근 30일)
clear;clc;
V=[1 2 3 4];
A=3;
%preallocation
C=zeros(1,numel(V));
xSol=zeros(1,numel(V));
ySol=zeros(1,numel(V));
for i=1:numel(V)
C(i)=V(i)-A;
syms x y
eqn1=C(i)*x+y==2;
eqn2=-x+y==3;
sol=solve([eqn1 eqn2],[x y]);
xSol(i)=double(sol.x);
ySol(i)=double(sol.y);
end
  댓글 수: 2
Mathieu NOE
Mathieu NOE 2021년 1월 27일
hello
at which line do you get the error ?
what is the error message in the command window ?
Pablo Zarco
Pablo Zarco 2021년 1월 27일
This is the message in the command window
Unable to perform assignment because the left and right sides have a different number of elements.
Error in Untitled2 (line 14)
xSol(i)=double(sol.x);

댓글을 달려면 로그인하십시오.

답변 (1개)

David Hill
David Hill 2021년 1월 27일
I would avoid symbolic if you can
V=[1 2 3 4];
A=3;
Sol=zeros(2,length(V));
for i=1:length(V)
Sol(:,i)=[V(i)-A,1;-1,1]\[2;3];
end

카테고리

Help CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by