Borrar filtros
Borrar filtros

How do I substract like variables from each other

2 visualizaciones (últimos 30 días)
Elysia
Elysia el 2 de Dic. de 2022
Respondida: Voss el 3 de Dic. de 2022
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 comentarios

Iniciar sesión para comentar.

Respuestas (2)

Arif Hoq
Arif Hoq el 2 de Dic. de 2022
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 el 3 de Dic. de 2022
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

Categorías

Más información sobre Resizing and Reshaping Matrices en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by