element wise operation column matrix

조회 수: 1 (최근 30일)
vishakha nagarajan
vishakha nagarajan 2021년 5월 25일
댓글: Stephan 2021년 5월 25일
I have a column matrix of data , Temp_data= [20;27;29;33;40] , i want to subtract each element i, by the first element (i.e 20-20; 27-20; 29-20;33-20), how do i do this?
also, how to do the similar operation if i have to subtract consequtive elements, i.e A(n) - A(n-1) [ex: 20-20; 27-20; 29-27....]

답변 (2개)

Stephan
Stephan 2021년 5월 25일
Temp_data= [20;27;29;33;40]
Temp_data = 5×1
20 27 29 33 40
Case_1 = Temp_data - Temp_data(1)
Case_1 = 5×1
0 7 9 13 20
Case_2 = diff(Temp_data)
Case_2 = 4×1
7 2 4 7

Stephen23
Stephen23 2021년 5월 25일
T = [20;27;29;33;40];
A = T - T(1)
A = 5×1
0 7 9 13 20
B = [0;diff(T)]
B = 5×1
0 7 2 4 7
  댓글 수: 1
Stephan
Stephan 2021년 5월 25일
I thought about adding zero as first elemnt, since it is part of the desired result. But i think it does not meet the rquirement of A(n) - A(n-1) - so we'll see

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

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by