diffrence of vector element and addition element- wise

조회 수: 1 (최근 30일)
Rica
Rica 2013년 2월 19일
hi!
i have a vector
%
A=[1 2 3 98 99 102]
i calculate the difference betwen thelement with the function diff
%
B=[ 1 1 95 1 3]
how could i manipulte vector A in this manner
%
BB=[A(1) A(1)+B(1)*5 A(2)+B(2)*5 A(3)+B(3)*5 ....A(5)+B(5)*5]
Thank you!

채택된 답변

José-Luis
José-Luis 2013년 2월 19일
A=[1 2 3 98 99 102];
BB = [A(1) ( A(1:numel(A)-1) + diff(A) ).*5]
  댓글 수: 1
Jos (10584)
Jos (10584) 2013년 2월 19일
... which is mathematically the same as
[A(1) A(2:numel(A))*5]
So, no need for diff(A) at all!

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

추가 답변 (1개)

Jos (10584)
Jos (10584) 2013년 2월 19일
A = [1 2 3 98 99 102];
BB = [A(1) A(2:numel(A))*5]
  댓글 수: 1
José-Luis
José-Luis 2013년 2월 19일
편집: José-Luis 2013년 2월 19일
Totally right.
+1
I blame it on not thinking.

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

카테고리

Help CenterFile Exchange에서 Get Started with Problem-Based Optimization and Equations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by