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

6 visualizzazioni (ultimi 30 giorni)
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?

Risposta accettata

KSSV
KSSV il 24 Mar 2022
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 Commento
lil brain
lil brain il 24 Mar 2022
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 );

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Programming in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by