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

2 views (last 30 days)
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.

Accepted Answer

Geoff Hayes
Geoff Hayes on 27 Apr 2019
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;

More Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!