Unable to perform assignment because the left and right sides have a different number of elements.

2 次查看(过去 30 天)
function g = untitled(x,y,z,t)
a = [1.2, -0.5, -1.7, 1.7];
b = [2.3, 1.5, 0.8, 1.4];
d = [0.2, 1.8, 1.3, -0.5];
e = [8.9844, 12.6636, 1.6423, 9.927];
c=0.047;
g = zeros(4, 1);
g(1) = (x-a(1)).^2+(y-b(1)).^2+(z-d(1)).^2-(c*(t-e(1))).^2;
g(2)= (x-a(2)).^2+(y-b(2)).^2+(z-d(2)).^2- (c*(t-e(2))).^2;
g(3)= (x-a(3)).^2+(y-b(3)).^2+(z-d(3)).^2- (c*(t-e(3))).^2;
g(4)= (x-a(4)).^2+(y-b(4)).^2+(z-d(4)).^2- (c*(t-e(4))).^2;
end
  4 个评论
Walter Roberson
Walter Roberson 2020-3-8
If your x, y, z, and t are scalar, then your code already works.
>> untitled(1,2,3,4)
ans =
7.91511906641776
3.77419695540336
11.6077207228184
13.022399312239
Srivardhan Gadila
Srivardhan Gadila 2020-3-14
@Haoang Sun, what do you mean by x,y,z,t are constants?
Clearly the cause of the error is either of x,y,z,t are non-scalars.

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 NaNs 的更多信息

产品


版本

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by