How to Loop through multiple columns of data

1 回表示 (過去 30 日間)
Micah Lierly
Micah Lierly 2018 年 1 月 3 日
コメント済み: Roger Stafford 2018 年 1 月 3 日
I have x & y coordinates for 2 points on a graph, 29 total graphs for each point. I need to loop through these coordinates for find the distance between the two points and then take the average. Right now I have x1 in a 29 x 1, y1 in a 29 x 1, x2 in a 29 x 1, and y2 in a 29 x 1. How do I loop through these points and find the distance between them?

回答 (1 件)

Roger Stafford
Roger Stafford 2018 年 1 月 3 日
average = mean(sqrt((x2-x1).^2+(y2-y1).^2));
  2 件のコメント
Micah Lierly
Micah Lierly 2018 年 1 月 3 日
My variables for the coordinates are all stored in 1x29 arrays. How do I write a for loop to loop through the 4 arrays, pulling out the corresponding x & y for the 2 points?
Roger Stafford
Roger Stafford 2018 年 1 月 3 日
The above code is designed to handle 1-by-29 arrays, all in one line. You don't need a for-loop for this task. Try it and see.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by