Why this gives error?

2 次查看(过去 30 天)
Sadiq Akbar
Sadiq Akbar 2022-4-15
评论: Voss 2022-4-16
LB=[0 0 0 0];
UB=[10 10 pi pi];
particles_x(1,1)=LB+rand*(UB-LB)
Unable to perform assignment because the indices on the left side are not compatible with the size of the right side.
  1 个评论
Jan
Jan 2022-4-15
I've added the error message. Please care for including the message in future questions about errors.

请先登录,再进行评论。

回答(2 个)

Jan
Jan 2022-4-15
LB = [0 0 0 0];
UB = [10 10 pi pi];
size(LB + rand * (UB - LB))
ans = 1×2
1 4
You cannot assign a [1 x 4] vector to the scalar particles_x(1,1).

KuriGohan
KuriGohan 2022-4-15
You get a 1x4 array on the right that you want to save inside the first row of the first column of the array - you cant do that. Just write particles_x=LB+rand*(UB-LB) and then particles_x(1,1) to acess what you want (at least what i think you want, that is the first element of that matrix).
  5 个评论
Jan
Jan 2022-4-16
What are "-ve values" ?
Voss
Voss 2022-4-16
I gather "-ve" means "negative" (so the "-" stands for "negati", I guess).

请先登录,再进行评论。

类别

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

Community Treasure Hunt

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

Start Hunting!

Translated by