Filter löschen
Filter löschen

subtract values inside a array

3 Ansichten (letzte 30 Tage)
Mohamed Musni
Mohamed Musni am 22 Jan. 2018
Kommentiert: Mohamed Musni am 22 Jan. 2018
any help will be great. Thank you

Akzeptierte Antwort

Stephen23
Stephen23 am 22 Jan. 2018
Bearbeitet: Stephen23 am 22 Jan. 2018
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
  1 Kommentar
Mohamed Musni
Mohamed Musni am 22 Jan. 2018
Thank you very much. have a nice day

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (2)

Birdman
Birdman am 22 Jan. 2018
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)
  1 Kommentar
Mohamed Musni
Mohamed Musni am 22 Jan. 2018
Thank you very much. this will help me a lot. have a nice day!

Melden Sie sich an, um zu kommentieren.


Mohammed Bahubayl
Mohammed Bahubayl am 22 Jan. 2018
Bearbeitet: Mohammed Bahubayl am 22 Jan. 2018
function output =difff(x)
intial=50;
output=[];
for i=1:length(x)
output(end+1)=intial-x(i);
intial=output(end);
end
end
  1 Kommentar
Mohamed Musni
Mohamed Musni am 22 Jan. 2018
thank you very much. have a nice day

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Cell Arrays finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by