difference between adjacent elements of a vector

조회 수: 12 (최근 30일)
Fidele Adanvo
Fidele Adanvo 2020년 11월 28일
편집: Fidele Adanvo 2020년 11월 28일
If I need to calculate the difference between the adjacent elements and know the size of the vector a priori, you will know what to tell me?
Por exemple..
A=[1,4,6,10,33,200,..............................]; A is
out=[A(1)-A(2), A(2)-A(3), A(3)-A(4),...........A(n-1)-A(n)]
Important vector "A" do not follow any rule or sequence. A is a matrix of size n whose value of n is not known a priori.

채택된 답변

Ameer Hamza
Ameer Hamza 2020년 11월 28일
편집: Ameer Hamza 2020년 11월 28일
A = [1,4,6,10,33,200];
out = A(1:end-1) - A(2:end);
  댓글 수: 1
Fidele Adanvo
Fidele Adanvo 2020년 11월 28일
편집: Fidele Adanvo 2020년 11월 28일
if A=[300 499 599 866 886 1000] valores stored value
n1=[1 2 6 ] the position that n1 occupies in A. for exemple n1(1)=300, n1(2)=499 and n1(3)=1000
n2=[ 3 4 5] the position that n2 occupies in A. for exemple n1(1)=599, n1(2)=866 and n1(3)=886.
if n1(1)=0 and n2(1)=0 i wiil have n1=[2 6 ] n2=[ 4 5] and A(n1(1))=0 and A(n2(1) ) =0
A=[499 866 886 1000] .
How to update automatically the new position occupied by n1 and n2 in the new A?
With this example you can see that n1=[1 4 ] n2=[ 2 3].

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by