Create a difference loop from a cumulative matrix
8 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Mohamed Amine Mouajib
el 8 de Abr. de 2019
Respondida: Mohamed Amine Mouajib
el 8 de Abr. de 2019
Hello
I have this data filed that I imported into a 831x1 matrix. The numbers in it are cumulative so I need to create a for loop that shows the difference between the row and the one before it so that I can have the pure added quantity in each row. If possible, I would like the first row to stay the same as it was in the imported file.
How do I do this?
4 comentarios
Respuesta aceptada
Raj
el 8 de Abr. de 2019
Suppose 'A' is your 831x1 matrix. Use this:
B=diff(A);
Apure=[A(1);B];
If you are specific with "for loop" then you can use this:
Apure=zeros(831,1);
Apure(1)=A(1);
for i=2:831
Apure(i)=A(i)-A(i-1);
end
3 comentarios
madhan ravi
el 8 de Abr. de 2019
Editada: madhan ravi
el 8 de Abr. de 2019
@Mohammed: Why is there a loop in your code?, even without the loop you would get the same result. Basically you are just repeating the same calculation over and over again.
Más respuestas (1)
Ver también
Categorías
Más información sobre Loops and Conditional Statements en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!