Sum of array as an others array value

Hi everyone, im new and this is my first question here.
I’m wondering why this is not possible:

If i Type:

A=[1.0, 2.0, 3.0, 4.0, 5.0];
B=zeros(5);

and then

sum(A)=B[1]

i get the error Message:

error in method definition: function Base.sum must be explicitly imported to be extended

Why is this ?

Typing

typeof(sum(A))

its Float64 like the elements of B?

also

sum(A[1:3])=B[1]

does not work , but now with the error mesasage:

syntax: "A[1:3]" is not a valid function argument name

Thanks

You can’t extend a Base method without importing it first. sum(A) = B[1] is a method definition, this is entirely different from just typing sum(A), because = is an assignment operator.

sum(A[1:3])=B[1] is invalid syntax.

Welcome!

Perhaps it would be useful if you explain what you’re trying to do, or what you expect to happen?

Also, to show code please use backticks (`) or triple-backticks(```) (I took the liberty of editing your post).

1 Like

It is not clear from your question what you really want to do or what is the expected behavior that you assumed. Perhaps you mean to do this?

A = [1.0, 2.0, 3.0, 4.0, 5.0]
B = zeros(5)

B[1] = sum(A)
B[1] = sum(A[1:3]) 
1 Like

Seif_Shebl, you are right, that is what i really wanted t do…and it works fine.
what a stupid mistake of mine…
Thanks a lot for the answers to everybody.