Why am I getting: Error using sum - Invalid option. Option must be 'double', 'native', 'default', 'omitnan', or 'includenan'.

22 次查看(过去 30 天)
Hi,
I have this for loop:
n = numel(cell_of_doubles);
distances_1 = cell(1,n);
for dd = 1:n
distances_1{dd} = sqrt(sum(cell_of_doubles{dd}(:,1:3),1,1).^2);
end
Whenever I try to run it I get the error,
Error using sum
Invalid option. Option must be 'double', 'native', 'default', 'omitnan', or 'includenan'.
It isn't clear to me why that is since my cell of doubles array is a double.
Does anyone know how I can solve this?

采纳的回答

KSSV
KSSV 2022-3-24
Repalce this line:
distances_1{dd} = sqrt(sum(cell_of_doubles{dd}(:,1:3),1,1).^2);
with
distances_1{dd} = sqrt(sum(cell_of_doubles{dd}(:,1:3),1).^2);
  1 个评论
lil brain
lil brain 2022-3-24
This only gives me a cell array where each cell contains three values as a vector like so:
distances_1{1}
ans =
418.29 834.61 402.12
but what I want to create is a list of differences where line 1 is subtracted from line 2 and line 2 is subtracted from line 3 and line 3 is subtracted from line 4 and so on.
This is my original function which I am trying to make into a for loop:
distances_1 = sqrt( dx.^2 + dy.^2 + dz.^2 );

请先登录,再进行评论。

更多回答(0 个)

类别

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

Community Treasure Hunt

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

Start Hunting!

Translated by