Straight line from all points of A to every single point of B

1 回表示 (過去 30 日間)
Riccardo Rossi
Riccardo Rossi 2019 年 3 月 12 日
編集済み: Jan 2019 年 3 月 12 日
Hi everybody,
i have 2 array with different number of rows (with columns that indicate x, y and z):
A (3x3 duble)
2.5 6.6 9.5
1.6 6.6 2.8
2.6 0.9 1.8
B (4x3 duble)
2.4 6.7 9.8
2.6 6.9 7.8
2.9 7.7 5.8
3.4 8.8 4.8
I want to track the straight line which passes from all points of A to every single point of B. I made this script but it does not run:
[m,n]=size(B)
[o,p]=size(A)
STR=-20:.01:20;
for i = 1:m
C{i}=repmat(A(1:o,:),length(STR),1)'+((B(i,:))-A(1:o,:))'*STR;
end
How can i do it? Thank you!
  3 件のコメント
Riccardo Rossi
Riccardo Rossi 2019 年 3 月 12 日
編集済み: Riccardo Rossi 2019 年 3 月 12 日
Thank you for the answer. I would like to obtain something like this:
C{1,1}=repmat(A(1,:),length(STR),1)'+((B(1,:))-A(1,:))'*STR;
C{1,2}=repmat(A(1,:),length(STR),1)'+((B(2,:))-A(1,:))'*STR;
C{1,3}=repmat(A(1,:),length(STR),1)'+((B(3,:))-A(1,:))'*STR;
C{1,4}=repmat(A(1,:),length(STR),1)'+((B(4,:))-A(1,:))'*STR;
C{1,5}=repmat(A(2,:),length(STR),1)'+((B(1,:))-A(2,:))'*STR;
C{1,6}=repmat(A(2,:),length(STR),1)'+((B(2,:))-A(2,:))'*STR;
C{1,7}=repmat(A(2,:),length(STR),1)'+((B(3,:))-A(2,:))'*STR;
C{1,8}=repmat(A(2,:),length(STR),1)'+((B(4,:))-A(2,:))'*STR;
C{1,9}=repmat(A(3,:),length(STR),1)'+((B(1,:))-A(3,:))'*STR;
C{1,10}=repmat(A(3,:),length(STR),1)'+((B(2,:))-A(3,:))'*STR;
C{1,11}=repmat(A(3,:),length(STR),1)'+((B(3,:))-A(3,:))'*STR;
C{1,12}=repmat(A(3,:),length(STR),1)'+((B(4,:))-A(3,:))'*STR;
Riccardo Rossi
Riccardo Rossi 2019 年 3 月 12 日
Is it possible?

サインインしてコメントする。

採用された回答

Jan
Jan 2019 年 3 月 12 日
編集済み: Jan 2019 年 3 月 12 日
With some guessing:
nB = size(B, 1)
nA = size(A, 1)
STR = -20:.01:20;
n = numel(STR);
C = cell(1, nA * nB);
iC = 0;
for iA = 1:nA
for iB = 1:nB
iC = iC + 1;
C{iC} = repmat(A(iA,:), n, 1).' + (B(iB, :) - A(iA, :)).' * STR;
end
end
As far as I can see, you can omit the repmat in Matlab >= 2016b.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

製品


リリース

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by