Error when calculating the distance between two three-dimensional points

6 ビュー (過去 30 日間)
lil brain
lil brain 2023 年 5 月 8 日
回答済み: Walter Roberson 2023 年 5 月 8 日
Hi,
I have a cell array that contains cells in which there are numerical arrays with 9 columns. In that numerical array the columns 1-3 are x, y, and z coordinates of point A. The columns 4-6 are x, y, and z coordinates of point B. And the columns 7-9 are x, y, and z coordinates of point C.
I wrote this code to measure the distances between point C and A.
for i = 1:numel(pre_xyz)
right_hand{i} = sqrt((pre_xyz{i}(:,7)-pre_xyz{i}(:,1)).^2 + (pre_xyz{i}(:,8)-pre_xyz{i}(:,2)).^2 + (pre_xyz{i}(:,9)-pre_xyz{i}(:,3)).^2);
end
But I get this error:
Operator '-' is not supported for operands of type 'cell'.
What is the easiest fix for this?
Thanks!
  1 件のコメント
Walter Roberson
Walter Roberson 2023 年 5 月 8 日
I have a cell array that contains cells in which there are numerical arrays with 9 columns.
load pre_xyz
pre_xyz{1}(1:5,:)
ans = 5×9 cell array
{[-0.2839]} {[1.6748]} {[-0.2873]} {[-0.2134]} {[1.3676]} {[-0.5863]} {[-0.0471]} {[1.3579]} {[-0.5301]} {[-0.2839]} {[1.6748]} {[-0.2873]} {[-0.2124]} {[1.3671]} {[-0.5861]} {[-0.0474]} {[1.3579]} {[-0.5299]} {[-0.2839]} {[1.6748]} {[-0.2873]} {[-0.2124]} {[1.3671]} {[-0.5861]} {[-0.0474]} {[1.3579]} {[-0.5299]} {[-0.2838]} {[1.6748]} {[-0.2866]} {[-0.2130]} {[1.3676]} {[-0.5846]} {[-0.0475]} {[1.3576]} {[-0.5286]} {[-0.2838]} {[1.6748]} {[-0.2866]} {[-0.2130]} {[1.3676]} {[-0.5845]} {[-0.0475]} {[1.3576]} {[-0.5286]}
No you do not. You have a cell array that contains cell arrays.

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

採用された回答

Walter Roberson
Walter Roberson 2023 年 5 月 8 日
for i = 1:numel(pre_xyz)
this_pre = cell2mat(pre_xyz{i});
right_hand{i} = sqrt((this_pre(:,7)-this_pre(:,1)).^2 + (this_pre(:,8)-this_pre(:,2)).^2 + (this_pre(:,9)-this_pre(:,3)).^2);
end

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeOperators and Elementary Operations についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by