필터 지우기
필터 지우기

How do I substract like variables from each other

조회 수: 1 (최근 30일)
Elysia
Elysia 2022년 12월 2일
답변: Voss 2022년 12월 3일
I have a table that looks like Book1_1, I need help with figuring out if Var1 row 1 ==Var1 row 2 then subtract Var2 row 2 from Var2 row 1 and continue down till the end of the table (this subtract answer would then create a new variable but I do not need help with creating a new variable just how to subtract likes from likes). Thank you.
  댓글 수: 3

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

답변 (2개)

Arif Hoq
Arif Hoq 2022년 12월 2일
one approach:
a=readmatrix("Book1.xlsx");
b= datetime(a,'ConvertFrom','excel');
% b(:,3)=b(:,2);
for i=1:size(b,1)-1
if b(i,1)==b(i+1,1)
c(i)=b(i+1,2)-b(i,2);
end
end
output=c'
output = 5×1 duration array
00:05:00 00:04:49 00:10:10 00:00:00 00:02:19

Voss
Voss 2022년 12월 3일
a = readmatrix("Book1.xlsx");
b = datetime(a(:,2),'ConvertFrom','excel');
N = size(a,1);
c = duration(NaN(N,3));
for i = 1:N-1
if a(i,1) == a(i+1,1)
c(i+1) = b(i+1)-b(i);
end
end
disp(c);
NaN 00:05:00 00:04:49 00:10:10 NaN 00:02:19

카테고리

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

태그

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by