matlab - 将 3d 坐标存储在点列表中 Matlab

标签 matlab list random coordinates points

我目前面临标题中提到的问题。 如果我只想拥有 3 个单独的点并将它们记录为在 matlab 中具有 3 个坐标的点很容易,如下所示

A=[0 0 1];%coordinates of Q1
B=[0 0 -1];%coordinates of Q2
C=[0 1 0];%coordinates of Q3

因此,描述了A(0,0,1)、B(0,0,-1)、C(0,1,0)的坐标。在进一步的计算中,我可以使用坐标并进行如下计算:

R1=A-B; %vector from Q2 to Q1
R2=A-C; %vector from Q3 to Q1
R3=C-B; %vector from Q2 to Q3

但是,如果我想生成很多点,比如随机生成 100 个点,我上面写的方式是愚蠢的。而且我也想像以前一样使用坐标来做,因为它更方便。下面是我试过的方法。

% random distributed points
x = rand(Number_of_Points, 1);
y = rand(Number_of_Points, 1);
z = x.^2 + y.^2;

Points = [x(:) y(:) z(:)];

但是它只记录了所有点的3个坐标我不能像以前那样单独记录它们。我想通过使用 Points(1)-Points(2) 计算矢量 有谁知道如何做吗?

最佳答案

你只需要使用下标索引而不是线性索引:

Points(1,:) - Points(2,:)

否则,如果你想要欧氏距离,你可以这样做

 sqrt(sum((Points(1,:) - Points(2,:)).^2))

或者让自己成为一个匿名函数:

PointsDistance = @(a,b)(sqrt(sum((Points(a,:) - Points(b,:)).^2)))

现在你可以调用

PointsDistance(1,2)

关于matlab - 将 3d 坐标存储在点列表中 Matlab,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26157579/

相关文章:

matlab - matlab循环索引

matlab - 通过将数字分组到一个范围内来在 matlab/octave 中绘图

javascript - 更改当前 li 类(被点击的那个)

matlab - matlab中的ICA(独立成分分析)

linux - 哪个 Linux 发行版附带了 4.3.4 的 gcc?

python - 以迭代和递归的方式交换列表中的对 -Python3

Python:列表中完整字符串与部分字符串的交集

c - 在 C 中为加密目的生成伪随机数的最简单方法是什么?

python - 如何洗牌列表中的项目,同时避免任何项目留在原来的位置?

JavaScript:Math.random:如何选择 190 到 255 之间的随机数 "unevenly",而不是 "evenly"?