天天看點

matlab刷題,由淺入深(3)

文章目錄

求輸入向量×的所有數字的總和

Examples:

Input  x = [1 2 3 5]
Output y is 11

Input  x = [42 -1]
Output y i 41      

函數:

function y = vecsum(x)
    y = sum(x);
    fprintf('y is %d',y);
end      

主函數:

% Use this area as a scratchpad to test code that you don't want to submit:
x =[1 2 3 4];
% Or call your function:
vecsum(x);
% Note this code will NOT be used for submit      

結果:

matlab刷題,由淺入深(3)

繼續閱讀