Why am i getting complex number?

조회 수: 1 (최근 30일)
Moe Lwin Nang Swe Zin
Moe Lwin Nang Swe Zin 2023년 3월 29일
답변: Fangjun Jiang 2023년 3월 29일
pos =zeros(num,2);
for j=1:num
pos(j,1)= 200*rand(1);
pos(j,2) = 200*rand(1);
end
I was trying to get positions and i am getting complex number in workspace. When i tried to display, it was real number. Why is workspace storing complex number?
  댓글 수: 1
Fangjun Jiang
Fangjun Jiang 2023년 3월 29일
What do you mean? You can run it here and see results.
num=3;
pos =zeros(num,2);
for j=1:num
pos(j,1)= 200*rand(1);
pos(j,2) = 200*rand(1);
end
pos
pos = 3×2
38.2616 166.3305 64.2819 142.4279 68.3623 17.7350

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

답변 (1개)

Fangjun Jiang
Fangjun Jiang 2023년 3월 29일
Are you sure you got complex numbers? Complex numbers are like below.
clear i j;
i
ans = 0.0000 + 1.0000i
j
ans = 0.0000 + 1.0000i
a=2+3i
a = 2.0000 + 3.0000i
b=4-5j
b = 4.0000 - 5.0000i

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by