필터 지우기
필터 지우기

subtract values inside a array

조회 수: 3 (최근 30일)
Mohamed Musni
Mohamed Musni 2018년 1월 22일
댓글: Mohamed Musni 2018년 1월 22일
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
  댓글 수: 1
Mohamed Musni
Mohamed Musni 2018년 1월 22일
Thank you very much. have a nice day

댓글을 달려면 로그인하십시오.

추가 답변 (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)
  댓글 수: 1
Mohamed Musni
Mohamed Musni 2018년 1월 22일
Thank you very much. this will help me a lot. have a nice day!

댓글을 달려면 로그인하십시오.


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
  댓글 수: 1
Mohamed Musni
Mohamed Musni 2018년 1월 22일
thank you very much. have a nice day

댓글을 달려면 로그인하십시오.

카테고리

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