How can I rewrite this in a simple short code

조회 수: 1 (최근 30일)
Jorge Arturo Clares Pastrana
Jorge Arturo Clares Pastrana 2022년 1월 21일
댓글: Walter Roberson 2022년 1월 21일
MID is a 1 x 15 Matrix with numerical val
ea1 = 1;
ea2 = ((MID(1,2)-MID(1,1))/(MID(1,2)));ea3 = ((MID(1,3)-MID(1,2))/(MID(1,3)));
ea4 = ((MID(1,4)-MID(1,3))/(MID(1,4)));ea5 = ((MID(1,5)-MID(1,4))/(MID(1,5)));
ea6 = ((MID(1,6)-MID(1,5))/(MID(1,6)));ea7 = ((MID(1,7)-MID(1,6))/(MID(1,7)));
ea8 = ((MID(1,8)-MID(1,7))/(MID(1,8)));ea9 = ((MID(1,9)-MID(1,8))/(MID(1,9)));ea10 = ((MID(1,10)-MID(1,9))/(MID(1,10)));
ea11 = ((MID(1,11)-MID(1,10))/(MID(1,11)));ea12 = ((MID(1,12)-MID(1,11))/(MID(1,12)));ea13 = ((MID(1,13)-MID(1,12))/(MID(1,13)));ea14 = ((MID(1,14)-MID(1,13))/(MID(1,14)));ea15 = ((MID(1,15)-MID(1,14))/(MID(1,15)));
EA = abs([ea1;ea2;ea3;ea4;ea5;ea6;ea7;ea8;ea9;ea10;ea11;ea12;ea13;ea14;ea15]);

채택된 답변

Voss
Voss 2022년 1월 21일
EA = abs([1 (MID(2:end)-MID(1:end-1))./MID(2:end)].');
  댓글 수: 3
Voss
Voss 2022년 1월 21일
You're welcome!
Walter Roberson
Walter Roberson 2022년 1월 21일
(MID(2:end)-MID(1:end-1))
looks as if it could be done more compactly as diff(MID)

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Interpolation에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by