How do i sum the total elements in a vector, not whats in each element

2 次查看(过去 30 天)
Hi im doing a project involving movements and I have to calculate the path each itteration takes, and i also have to see which path is overall the shortest (the best in this case). Is there anyway to use the sum function to sum the total number of movements and not the cordiantes inside the vector. if i have [ 3 4, 2 5] I want it to sum the total movements as two and not combine the numbers.

采纳的回答

Geoff Hayes
Geoff Hayes 2019-4-27
caitlin - if your movements are in a matrix, say nx2, where each row is a coordinate for the movement, then the number of movements is equivalent to the number of rows
movementCoodinates = ...; % your coordinates
numberOfCoordinates = size(movementCoodinates, 1);
Can your data be put in this (or a similar format)? Else, if you just have a row array (like your example above of [3 4 2 5]), then the number of movements is just the number of columns divided by two
movementCoodinates = ...; % your coordinates
numberOfCoordinates = size(movementCoodinates, 2) / 2;

更多回答(0 个)

标签

Community Treasure Hunt

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

Start Hunting!

Translated by