方法一:使用matlab自带的函数 cumsum
clc;clear; a=20:54; cumsum(a)
方法二:自己编写程序
clc;clear; a = 20:54; sum_vec = zeros(1,length(a)); sum_a = 0; for ii = 1:length(a); sum_a = sum_a+ a(ii); sum_vec(ii) = sum_a; end figure plot(sum_vec)
方法一:使用matlab自带的函数 cumsum
clc;clear; a=20:54; cumsum(a)
方法二:自己编写程序
clc;clear; a = 20:54; sum_vec = zeros(1,length(a)); sum_a = 0; for ii = 1:length(a); sum_a = sum_a+ a(ii); sum_vec(ii) = sum_a; end figure plot(sum_vec)