MATLAB Answers

How can I move through an array and a vector that need to be compared?

5 ビュー (過去 30 日間)
Andreea Juravschi
Andreea Juravschi 2019 年 10 月 29 日
回答済み: Shubham Gupta 2019 年 10 月 29 日
I have an Excel file that changed to an array after using the xlsread file, and ahve those values as well as a given vector of numebrs that I essentially need to compare using a euclidean distance formula. Basically the second, third ,and fourth columns are coordinates of airplanes and the vector given has the coordinates of a separate airplane. The coordinates of each are plugged into the formula and if the distance calculated is less than a given distance- the planes crash, and you print another cell array file of the same variation. i'm just not sure how to take the array of all the planes and their coordinates and move through them to plug in different values in the equation without hard coding?
  1 件のコメント
Shubham Gupta
Shubham Gupta 2019 年 10 月 29 日
Few questions:
"the vector given has the coordinates of a separate airplane" - what is the dimesion of the vector?
"you print another cell array file of the same variation" - cell array file, what do mean by that? and variation depends on which parameter?
"move through them to plug in different values in the equation" what do you mean by "move through" & which equation are you talking about?
Best way to explain the question is through some examples with necessary output. Cheers

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

回答 (1 件)

Shubham Gupta
Shubham Gupta 2019 年 10 月 29 日
My undersanding for the question.
For example you have a coordinates of 4 test planes (X) & coordinate for a separate reference plane (Y)
X = [1,2,3;
7,8,9;
4,5,6;
10,11,12];
Y = [1.4,1.5,1.6];
You first want to calculate distance of each plane in X with respect to (w.r.t.) Y, using
d = sqrt(sum(bsxfun(@minus,X,Y).^2,2)); % will produce column vector d of length = size(X,1),
% containing distance of coordinates in X wrt Y coordiante
Now, you want to put some kind of inequility to show with plane will crash, using a cell array?
d_limit = 7; % distance limit to predict whether plane will crash or not
JudgementCell = cell(size(d)); % prelocate cell array
JudgementCell(:,1) = {'No'}; % assign all cells as 'No' meaning plane won't crash
JudgementCell(d < d_limit) = {'Yes'}; % cells with d<d_limit will crash, so assign 'Yes'
Let me know if this is what you want or if you have any doubts.

製品


リリース

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by