subtract values inside a array

3 次查看(过去 30 天)
any help will be great. Thank you

采纳的回答

Stephen23
Stephen23 2018-1-22
编辑:Stephen23 2018-1-22
MATLAB code should be beautiful, simple, and efficient:
>> V = [12;2;6;8;6;2;12];
>> 50+cumsum(-V)
ans =
38
36
30
22
16
14
2

更多回答(2 个)

Birdman
Birdman 2018-1-22
Not the most efficient, but a solution:
init=50;
a=[init 12 2 6 8 6 2 12]
for i=1:numel(a)-1
val=a(1)-a(2);
b(i)=val;
a(1)=[];
a(1)=val;
end
disp(b)

Mohammed Bahubayl
Mohammed Bahubayl 2018-1-22
编辑:Mohammed Bahubayl 2018-1-22
function output =difff(x)
intial=50;
output=[];
for i=1:length(x)
output(end+1)=intial-x(i);
intial=output(end);
end
end

类别

Help CenterFile Exchange 中查找有关 Cell Arrays 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by