problem with sum in function
Ältere Kommentare anzeigen
Hello every one!
I am new with matlab and i have a problem with very simple program with matlab 2019a
Code 1:
clear all;
z=so;
function [s] = so
A=[1 5 3 4 2 10 21 65];
s = sum(A);
s = s+1;
end
The answer is z=112, it's correct
Code 2:
clear all;
A=[1 5 3 4 2 10 21 65];
z=so;
function [s] = so
s = sum(A);
s = s+1;
end
I get this error

So as far as i understand, "Sum" can not read the variable out of the function "so".
DId i do somethings wrong or my computer have issues?
It's just a little test, but i need to get work with "sum" in a function so I can write a bigger program.
Akzeptierte Antwort
Weitere Antworten (1)
Fangjun Jiang
am 22 Apr. 2020
0 Stimmen
You are right. All you need to do is "function [s] = so(A)" to pass in the value of A.
2 Kommentare
ronaldo messi
am 22 Apr. 2020
Steven Lord
am 22 Apr. 2020
You're not a fool. You said you're new with MATLAB, and that means there are things you don't know. That's how everyone, with the possible exception of Cleve, started out. And Cleve is a bit of a special case, being the author of the first version of MATLAB.
Kategorien
Mehr zu Programming finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!