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

1 回表示 (過去 30 日間)
caitlin Leonowicz
caitlin Leonowicz 2019 年 4 月 27 日
回答済み: Geoff Hayes 2019 年 4 月 27 日
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 件)

カテゴリ

Help Center および File ExchangeGeometric Geodesy についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by